Skip to content

Commit

Permalink
Webhook Templates Resources, Data sources, Subscription changes and D…
Browse files Browse the repository at this point in the history
…ocumentation Update (IBM-Cloud#5713)
  • Loading branch information
Divya-Singh1693 authored Oct 22, 2024
1 parent 8b2bb36 commit 7b568a1
Show file tree
Hide file tree
Showing 20 changed files with 806 additions and 66 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/IBM/configuration-aggregator-go-sdk v0.0.1
github.com/IBM/container-registry-go-sdk v1.1.0
github.com/IBM/continuous-delivery-go-sdk v1.8.2
github.com/IBM/event-notifications-go-admin-sdk v0.9.0
github.com/IBM/event-notifications-go-admin-sdk v0.10.0
github.com/IBM/eventstreams-go-sdk v1.4.0
github.com/IBM/go-sdk-core v1.1.0
github.com/IBM/go-sdk-core/v3 v3.2.4
Expand Down Expand Up @@ -63,7 +63,7 @@ require (
github.com/rook/rook v1.11.4
github.com/softlayer/softlayer-go v1.0.3
github.com/stretchr/testify v1.9.0
golang.org/x/crypto v0.25.0
golang.org/x/crypto v0.27.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools v2.2.0+incompatible
k8s.io/api v0.26.3
Expand Down Expand Up @@ -105,7 +105,7 @@ require (
github.com/fatih/color v1.16.0 // indirect
github.com/frankban/quicktest v1.14.3 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand All @@ -121,7 +121,7 @@ require (
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/go-playground/validator/v10 v10.22.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand Down Expand Up @@ -212,7 +212,7 @@ require (
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
go.mongodb.org/mongo-driver v1.16.0 // indirect
go.mongodb.org/mongo-driver v1.16.1 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.uber.org/ratelimit v0.2.0 // indirect
Expand Down
35 changes: 18 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ github.com/IBM/container-registry-go-sdk v1.1.0 h1:sYyknIod8R4RJZQqAheiduP6wbSTp
github.com/IBM/container-registry-go-sdk v1.1.0/go.mod h1:4TwsCnQtVfZ4Vkapy/KPvQBKFc3VOyUZYkwRU4FTPrs=
github.com/IBM/continuous-delivery-go-sdk v1.8.2 h1:L2hyoJSxgCa0/HKviHKtut1z4Mn2qGz1gnJZ43LV0o0=
github.com/IBM/continuous-delivery-go-sdk v1.8.2/go.mod h1:5umVUaXEoTP2ULARgXRBPcR3vWDCmKD66P6XgNqpzZk=
github.com/IBM/event-notifications-go-admin-sdk v0.9.0 h1:eaCd+GkxhNyot+8rA9WkAQdlVYrRD20LYiXjEytFO6M=
github.com/IBM/event-notifications-go-admin-sdk v0.9.0/go.mod h1:OByvqfrNVxs7G6ggv8pwQCEVw10/TBJCLh7NM3z707w=
github.com/IBM/event-notifications-go-admin-sdk v0.10.0 h1:SbEG6Z9lJWQxNYexYmLRzF+seFokOW7bRKBgiyfYsls=
github.com/IBM/event-notifications-go-admin-sdk v0.10.0/go.mod h1:za2mdfBpox6hdsKaYTbE5ooCv2im8BYPq5yuKc7x5Ao=
github.com/IBM/eventstreams-go-sdk v1.4.0 h1:yS/Ns29sBOe8W2tynQmz9HTKqQZ0ckse4Py5Oy/F2rM=
github.com/IBM/eventstreams-go-sdk v1.4.0/go.mod h1:2tuAxaYLctfqfr5jvyqSrxxEQGMwYPm3yJGWSj85YVQ=
github.com/IBM/go-sdk-core v1.1.0 h1:pV73lZqr9r1xKb3h08c1uNG3AphwoV5KzUzhS+pfEqY=
Expand Down Expand Up @@ -491,8 +491,9 @@ github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbS
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4=
github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4=
github.com/gammazero/deque v0.0.0-20190130191400-2afb3858e9c7/go.mod h1:GeIq9qoE43YdGnDXURnmKTnGg15pQz4mYkXSTChbneI=
github.com/gammazero/workerpool v0.0.0-20190406235159-88d534f22b56/go.mod h1:w9RqFVO2BM3xwWEcAB8Fwp0OviTBBEiRmSBDfbXnd3w=
github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg=
Expand Down Expand Up @@ -638,8 +639,8 @@ github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao=
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
Expand Down Expand Up @@ -1709,8 +1710,8 @@ go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4x
go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8=
go.mongodb.org/mongo-driver v1.11.3/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.mongodb.org/mongo-driver v1.16.0 h1:tpRsfBJMROVHKpdGyc1BBEzzjDUWjItxbVSZ8Ls4BQ4=
go.mongodb.org/mongo-driver v1.16.0/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4l8=
go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
go.opencensus.io v0.19.1/go.mod h1:gug0GbSHa8Pafr0d2urOSgoXHZ6x/RUlaiT0d9pqb4A=
go.opencensus.io v0.19.2/go.mod h1:NO/8qkisMZLZ1FCsKNqtJPwc8/TaclWyY0B6wcYNg9M=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
Expand Down Expand Up @@ -1789,8 +1790,8 @@ golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -1919,8 +1920,8 @@ golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190130055435-99b60b757ec1/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1958,8 +1959,8 @@ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -2091,8 +2092,8 @@ golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -2115,8 +2116,8 @@ golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
2 changes: 2 additions & 0 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ func Provider() *schema.Provider {
"ibm_en_slack_template": eventnotification.DataSourceIBMEnSlackTemplate(),
"ibm_en_metrics": eventnotification.DataSourceIBMEnMetrics(),
"ibm_en_smtp_allowed_ips": eventnotification.DataSourceIBMEnSMTPAllowedIps(),
"ibm_en_webhook_template": eventnotification.DataSourceIBMEnWebhookTemplate(),

// Added for Toolchain
"ibm_cd_toolchain": cdtoolchain.DataSourceIBMCdToolchain(),
Expand Down Expand Up @@ -1535,6 +1536,7 @@ func Provider() *schema.Provider {
"ibm_en_smtp_user": eventnotification.ResourceIBMEnSMTPUser(),
"ibm_en_slack_template": eventnotification.ResourceIBMEnSlackTemplate(),
"ibm_en_smtp_setting": eventnotification.ResourceIBMEnSMTPSetting(),
"ibm_en_webhook_template": eventnotification.ResourceIBMEnWebhookTemplate(),

// Added for Toolchain
"ibm_cd_toolchain": cdtoolchain.ResourceIBMCdToolchain(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func DataSourceIBMEnWebhookSubscription() *schema.Resource {
Computed: true,
Description: "Signing webhook attributes.",
},
"template_id_notification": {
Type: schema.TypeString,
Computed: true,
Description: "The templete id for notification",
},
"additional_properties": {
Type: schema.TypeMap,
Computed: true,
Expand Down Expand Up @@ -145,6 +150,10 @@ func enWebhookSubscriptionToMap(attributeItem *en.SubscriptionAttributes) (attri
attributeMap["signing_enabled"] = attributeItem.SigningEnabled
}

if attributeItem.TemplateIDNotification != nil {
attributeMap["template_id_notification"] = attributeItem.TemplateIDNotification
}

attributeMap["additional_properties"] = attributeItem.GetProperties()

return attributeMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ func DataSourceIBMEnSlackSubscription() *schema.Resource {
Schema: map[string]*schema.Schema{
"attachment_color": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "attachment color code",
},
"template_id_notification": {
Type: schema.TypeString,
Computed: true,
Description: "The templete id for notification",
},
"channels": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -151,6 +156,10 @@ func enSlackSubscriptionToMap(attributeItem *en.SubscriptionAttributes) (attribu
attributeMap["attachment_color"] = attributeItem.AttachmentColor
}

if attributeItem.TemplateIDNotification != nil {
attributeMap["template_id_notification"] = attributeItem.TemplateIDNotification
}

if attributeItem.Channels != nil {
channels := []map[string]interface{}{}
for _, channelsItem := range attributeItem.Channels {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func DataSourceIBMEnSlackTemplate() *schema.Resource {
"type": {
Type: schema.TypeString,
Computed: true,
Description: "Template type smtp_custom.notification/smtp_custom.invitation.",
Description: "Template type slack.notification.",
},
"updated_at": {
Type: schema.TypeString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,6 @@ func DataSourceIBMEnEmailSubscription() *schema.Resource {
Computed: true,
Description: "The email address username of source email address.",
},
// "invited": {
// Type: schema.TypeList,
// Optional: true,
// Computed: true,
// Description: "The email id to be invited",
// },
// "subscribed": {
// Type: schema.TypeList,
// Optional: true,
// Computed: true,
// Description: "The Email address which should be subscribed from smtp_ibm.",
// },
// "unsubscribed": {
// Type: schema.TypeList,
// Optional: true,
// Computed: true,
// Description: "The Email address which should be unsubscribed from smtp_ibm.",
// },
"invited": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -230,22 +212,6 @@ func enEmailSubscriptionFlattenAttributes(result en.SubscriptionAttributesIntf)
attributes := result.(*en.SubscriptionAttributes)

finalMap := enEmailSubscriptionToMap(attributes)
// finalList = append(finalList, finalMap)
// invitedmap := make(map[string]interface{})
// if attributes.Invited != nil {
// invitedmap["invited"] = attributes.Invited
// }
// finalList = append(finalList, invitedmap)
// subscribedmap := make(map[string]interface{})
// if attributes.Subscribed != nil {
// subscribedmap["subscribed"] = attributes.Subscribed
// }
// finalList = append(finalList, subscribedmap)
// unsubscribedmap := make(map[string]interface{})
// if attributes.Unsubscribed != nil {
// unsubscribedmap["unsubscribed"] = attributes.Unsubscribed
// }
// finalList = append(finalList, unsubscribedmap)
finalList = append(finalList, finalMap)

return finalList
Expand Down
117 changes: 117 additions & 0 deletions ibm/service/eventnotification/data_source_ibm_en_webhook_template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright IBM Corp. 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package eventnotification

import (
"context"
"fmt"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
en "github.com/IBM/event-notifications-go-admin-sdk/eventnotificationsv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceIBMEnWebhookTemplate() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMEnWebhookTemplateRead,

Schema: map[string]*schema.Schema{
"instance_guid": {
Type: schema.TypeString,
Required: true,
Description: "Unique identifier for IBM Cloud Event Notifications instance.",
},
"template_id": {
Type: schema.TypeString,
Required: true,
Description: "Unique identifier for Template.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Template name.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Templaten description.",
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "Template type webhook.notification.",
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "Last updated time.",
},
"subscription_count": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of subscriptions.",
},
"subscription_names": {
Type: schema.TypeList,
Computed: true,
Description: "List of subscriptions.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}

func dataSourceIBMEnWebhookTemplateRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
enClient, err := meta.(conns.ClientSession).EventNotificationsApiV1()
if err != nil {
return diag.FromErr(err)
}

options := &en.GetTemplateOptions{}

options.SetInstanceID(d.Get("instance_guid").(string))
options.SetID(d.Get("template_id").(string))

result, response, err := enClient.GetTemplateWithContext(context, options)
if err != nil {
return diag.FromErr(fmt.Errorf("GetTemplate failed %s\n%s", err, response))
}

d.SetId(fmt.Sprintf("%s/%s", *options.InstanceID, *options.ID))

if err = d.Set("name", result.Name); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err))
}

if result.Description != nil {
if err = d.Set("description", result.Description); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err))
}
}

if err = d.Set("type", result.Type); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting type: %s", err))
}

if result.SubscriptionNames != nil {
err = d.Set("subscription_names", result.SubscriptionNames)
if err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting subscription_names %s", err))
}
}

if err = d.Set("updated_at", flex.DateTimeToString(result.UpdatedAt)); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err))
}

if err = d.Set("subscription_count", flex.IntValue(result.SubscriptionCount)); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting subscription_count: %s", err))
}

return nil
}
Loading

0 comments on commit 7b568a1

Please sign in to comment.