-
Notifications
You must be signed in to change notification settings - Fork 639
/
resource_ibm_appid_theme_text.go
130 lines (100 loc) · 3.25 KB
/
resource_ibm_appid_theme_text.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package appid
import (
"context"
"log"
"github.com/IBM-Cloud/bluemix-go/helpers"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
appid "github.com/IBM/appid-management-go-sdk/appidmanagementv4"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func ResourceIBMAppIDThemeText() *schema.Resource {
return &schema.Resource{
Description: "Update theme texts of the App ID login widget",
CreateContext: resourceIBMAppIDThemeTextCreate,
ReadContext: resourceIBMAppIDThemeTextRead,
UpdateContext: resourceIBMAppIDThemeTextUpdate,
DeleteContext: resourceIBMAppIDThemeTextDelete,
Schema: map[string]*schema.Schema{
"tenant_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The AppID instance GUID",
},
"tab_title": {
Type: schema.TypeString,
Optional: true,
},
"footnote": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
func resourceIBMAppIDThemeTextRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
appIDClient, err := meta.(conns.ClientSession).AppIDAPI()
if err != nil {
return diag.FromErr(err)
}
tenantID := d.Id()
text, resp, err := appIDClient.GetThemeTextWithContext(ctx, &appid.GetThemeTextOptions{
TenantID: &tenantID,
})
if err != nil {
if resp != nil && resp.StatusCode == 404 {
log.Printf("[WARN] AppID instance '%s' is not found, removing AppID theme text configuration from state", tenantID)
d.SetId("")
return nil
}
return diag.Errorf("Error getting AppID theme text: %s\n%s", err, resp)
}
if text.TabTitle != nil {
d.Set("tab_title", *text.TabTitle)
}
if text.Footnote != nil {
d.Set("footnote", *text.Footnote)
}
d.Set("tenant_id", tenantID)
return nil
}
func resourceIBMAppIDThemeTextCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
appIDClient, err := meta.(conns.ClientSession).AppIDAPI()
if err != nil {
return diag.FromErr(err)
}
tenantID := d.Get("tenant_id").(string)
input := &appid.PostThemeTextOptions{
TenantID: &tenantID,
TabTitle: helpers.String(d.Get("tab_title").(string)),
Footnote: helpers.String(d.Get("footnote").(string)),
}
resp, err := appIDClient.PostThemeTextWithContext(ctx, input)
if err != nil {
return diag.Errorf("Error setting AppID theme text: %s\n%s", err, resp)
}
d.SetId(tenantID)
return resourceIBMAppIDThemeTextRead(ctx, d, meta)
}
func resourceIBMAppIDThemeTextUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
return resourceIBMAppIDThemeTextCreate(ctx, d, meta)
}
func resourceIBMAppIDThemeTextDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
appIDClient, err := meta.(conns.ClientSession).AppIDAPI()
if err != nil {
return diag.FromErr(err)
}
tenantID := d.Get("tenant_id").(string)
input := &appid.PostThemeTextOptions{
TenantID: &tenantID,
TabTitle: helpers.String("Login"),
Footnote: helpers.String("Powered by App ID"),
}
resp, err := appIDClient.PostThemeTextWithContext(ctx, input)
if err != nil {
return diag.Errorf("Error resetting AppID theme text: %s\n%s", err, resp)
}
d.SetId("")
return nil
}