|
| 1 | +package mongodbatlas |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" |
| 8 | + matlas "go.mongodb.org/atlas/mongodbatlas" |
| 9 | +) |
| 10 | + |
| 11 | +func dataSourceMongoDBAtlasThirdPartyIntegration() *schema.Resource { |
| 12 | + integration := thirdPartyIntegrationSchema() |
| 13 | + integration.Schema["project_id"] = &schema.Schema{ |
| 14 | + Type: schema.TypeString, |
| 15 | + Required: true, |
| 16 | + } |
| 17 | + |
| 18 | + integration.Schema["type"] = &schema.Schema{ |
| 19 | + Type: schema.TypeString, |
| 20 | + Required: true, |
| 21 | + Description: "Third-party service integration identifier", |
| 22 | + } |
| 23 | + |
| 24 | + integration.Read = dataSourceMongoDBAtlasThirdPartyIntegrationRead |
| 25 | + |
| 26 | + return integration |
| 27 | +} |
| 28 | + |
| 29 | +func thirdPartyIntegrationSchema() *schema.Resource { |
| 30 | + return &schema.Resource{ |
| 31 | + Schema: map[string]*schema.Schema{ |
| 32 | + "project_id": { |
| 33 | + Type: schema.TypeString, |
| 34 | + Computed: true, |
| 35 | + }, |
| 36 | + "type": { |
| 37 | + Type: schema.TypeString, |
| 38 | + Computed: true, |
| 39 | + }, |
| 40 | + "license_key": { |
| 41 | + Type: schema.TypeString, |
| 42 | + Sensitive: true, |
| 43 | + Computed: true, |
| 44 | + }, |
| 45 | + "account_id": { |
| 46 | + Type: schema.TypeString, |
| 47 | + Computed: true, |
| 48 | + }, |
| 49 | + "write_token": { |
| 50 | + Type: schema.TypeString, |
| 51 | + Sensitive: true, |
| 52 | + Computed: true, |
| 53 | + }, |
| 54 | + "read_token": { |
| 55 | + Type: schema.TypeString, |
| 56 | + Sensitive: true, |
| 57 | + Computed: true, |
| 58 | + }, |
| 59 | + "api_key": { |
| 60 | + Type: schema.TypeString, |
| 61 | + Sensitive: true, |
| 62 | + Computed: true, |
| 63 | + }, |
| 64 | + "region": { |
| 65 | + Type: schema.TypeString, |
| 66 | + Computed: true, |
| 67 | + }, |
| 68 | + "service_key": { |
| 69 | + Type: schema.TypeString, |
| 70 | + Sensitive: true, |
| 71 | + Computed: true, |
| 72 | + }, |
| 73 | + "api_token": { |
| 74 | + Type: schema.TypeString, |
| 75 | + Sensitive: true, |
| 76 | + Computed: true, |
| 77 | + }, |
| 78 | + "team_name": { |
| 79 | + Type: schema.TypeString, |
| 80 | + Computed: true, |
| 81 | + }, |
| 82 | + "channel_name": { |
| 83 | + Type: schema.TypeString, |
| 84 | + Computed: true, |
| 85 | + }, |
| 86 | + "routing_key": { |
| 87 | + Type: schema.TypeString, |
| 88 | + Sensitive: true, |
| 89 | + Computed: true, |
| 90 | + }, |
| 91 | + "flow_name": { |
| 92 | + Type: schema.TypeString, |
| 93 | + Computed: true, |
| 94 | + }, |
| 95 | + "org_name": { |
| 96 | + Type: schema.TypeString, |
| 97 | + Computed: true, |
| 98 | + }, |
| 99 | + "url": { |
| 100 | + Type: schema.TypeString, |
| 101 | + Computed: true, |
| 102 | + }, |
| 103 | + "secret": { |
| 104 | + Type: schema.TypeString, |
| 105 | + Sensitive: true, |
| 106 | + Computed: true, |
| 107 | + }, |
| 108 | + }, |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +func dataSourceMongoDBAtlasThirdPartyIntegrationRead(d *schema.ResourceData, meta interface{}) error { |
| 113 | + projectID := d.Get("project_id").(string) |
| 114 | + queryType := d.Get("type").(string) |
| 115 | + |
| 116 | + conn := meta.(*matlas.Client) |
| 117 | + |
| 118 | + integration, _, err := conn.Integrations.Get(context.Background(), projectID, queryType) |
| 119 | + |
| 120 | + if err != nil { |
| 121 | + return fmt.Errorf("error getting third party integration for type %s %w", queryType, err) |
| 122 | + } |
| 123 | + |
| 124 | + fieldMap := integrationToSchema(integration) |
| 125 | + |
| 126 | + for property, value := range fieldMap { |
| 127 | + if err = d.Set(property, value); err != nil { |
| 128 | + return fmt.Errorf("error setting %s for third party integration %w", property, err) |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + d.SetId(encodeStateID(map[string]string{ |
| 133 | + "project_id": projectID, |
| 134 | + "type": queryType, |
| 135 | + })) |
| 136 | + |
| 137 | + return nil |
| 138 | +} |
0 commit comments