Skip to content

Commit 35f8104

Browse files
committed
support for required default tags
1 parent b21864d commit 35f8104

16 files changed

+226
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Added
44
- Support DBaaS VM DB Fast Provisioning
5+
- Support for required default tags
56

67
### Fixed
78
- Fix compositeId parsing for pre-authenticated requests in object storage [Issue #867](https://github.com/terraform-providers/terraform-provider-oci/issues/867)

oci/identity_tag_default_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func (s *IdentityTagDefaultDataSourceCrud) SetData() error {
6666
s.D.Set("compartment_id", *s.Res.CompartmentId)
6767
}
6868

69+
if s.Res.IsRequired != nil {
70+
s.D.Set("is_required", *s.Res.IsRequired)
71+
}
72+
6973
s.D.Set("state", s.Res.LifecycleState)
7074

7175
if s.Res.TagDefinitionId != nil {

oci/identity_tag_default_resource.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package provider
44

55
import (
66
"context"
7+
"time"
78

89
"github.com/hashicorp/terraform/helper/schema"
910

@@ -38,6 +39,11 @@ func IdentityTagDefaultResource() *schema.Resource {
3839
},
3940

4041
// Optional
42+
"is_required": {
43+
Type: schema.TypeBool,
44+
Optional: true,
45+
Computed: true,
46+
},
4147

4248
// Computed
4349
"state": {
@@ -130,6 +136,11 @@ func (s *IdentityTagDefaultResourceCrud) Create() error {
130136
request.CompartmentId = &tmp
131137
}
132138

139+
if isRequired, ok := s.D.GetOkExists("is_required"); ok {
140+
tmp := isRequired.(bool)
141+
request.IsRequired = &tmp
142+
}
143+
133144
if tagDefinitionId, ok := s.D.GetOkExists("tag_definition_id"); ok {
134145
tmp := tagDefinitionId.(string)
135146
request.TagDefinitionId = &tmp
@@ -148,6 +159,16 @@ func (s *IdentityTagDefaultResourceCrud) Create() error {
148159
}
149160

150161
s.Res = &response.TagDefault
162+
163+
// service takes some time for the isRequired effect to get stabilized
164+
if isRequired, ok := s.D.GetOkExists("is_required"); ok {
165+
tmp := isRequired.(bool)
166+
167+
if tmp {
168+
time.Sleep(20 * time.Second)
169+
}
170+
}
171+
151172
return nil
152173
}
153174

@@ -171,6 +192,11 @@ func (s *IdentityTagDefaultResourceCrud) Get() error {
171192
func (s *IdentityTagDefaultResourceCrud) Update() error {
172193
request := oci_identity.UpdateTagDefaultRequest{}
173194

195+
if isRequired, ok := s.D.GetOkExists("is_required"); ok {
196+
tmp := isRequired.(bool)
197+
request.IsRequired = &tmp
198+
}
199+
174200
tmp := s.D.Id()
175201
request.TagDefaultId = &tmp
176202

@@ -187,6 +213,14 @@ func (s *IdentityTagDefaultResourceCrud) Update() error {
187213
}
188214

189215
s.Res = &response.TagDefault
216+
// service takes some time for the isRequired effect to get stabilized
217+
if isRequired, ok := s.D.GetOkExists("is_required"); ok && s.D.HasChange("is_required") {
218+
tmp := isRequired.(bool)
219+
220+
if tmp {
221+
time.Sleep(20 * time.Second)
222+
}
223+
}
190224
return nil
191225
}
192226

@@ -207,6 +241,10 @@ func (s *IdentityTagDefaultResourceCrud) SetData() error {
207241
s.D.Set("compartment_id", *s.Res.CompartmentId)
208242
}
209243

244+
if s.Res.IsRequired != nil {
245+
s.D.Set("is_required", *s.Res.IsRequired)
246+
}
247+
210248
s.D.Set("state", s.Res.LifecycleState)
211249

212250
if s.Res.TagDefinitionId != nil {

oci/identity_tag_default_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
)
1717

1818
var (
19+
TagDefaultRequiredOnlyResource = TagDefaultResourceDependencies +
20+
generateResourceFromRepresentationMap("oci_identity_tag_default", "test_tag_default", Required, Create, tagDefaultRepresentation)
21+
1922
TagDefaultResourceConfig = TagDefaultResourceDependencies +
2023
generateResourceFromRepresentationMap("oci_identity_tag_default", "test_tag_default", Optional, Update, tagDefaultRepresentation)
2124

@@ -46,6 +49,7 @@ var (
4649
"compartment_id": Representation{repType: Required, create: `${var.compartment_id}`},
4750
"tag_definition_id": Representation{repType: Required, create: `${oci_identity_tag.test_tag.id}`},
4851
"value": Representation{repType: Required, create: `W123`, update: `value2`},
52+
"is_required": Representation{repType: Optional, create: `true`, update: `false`},
4953
}
5054

5155
TagDefaultResourceDependencies = TagRequiredOnlyResource
@@ -91,13 +95,39 @@ func TestIdentityTagDefaultResource_basic(t *testing.T) {
9195
),
9296
},
9397

98+
// delete before next create
99+
{
100+
Config: config + compartmentIdVariableStr + TagDefaultResourceDependencies,
101+
},
102+
// verify create with optionals
103+
{
104+
Config: config + compartmentIdVariableStr + TagDefaultResourceDependencies +
105+
generateResourceFromRepresentationMap("oci_identity_tag_default", "test_tag_default", Optional, Create, tagDefaultRepresentation),
106+
Check: resource.ComposeAggregateTestCheckFunc(
107+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
108+
resource.TestCheckResourceAttrSet(resourceName, "id"),
109+
resource.TestCheckResourceAttr(resourceName, "is_required", "true"),
110+
resource.TestCheckResourceAttrSet(resourceName, "tag_definition_id"),
111+
resource.TestCheckResourceAttrSet(resourceName, "tag_definition_name"),
112+
resource.TestCheckResourceAttrSet(resourceName, "tag_namespace_id"),
113+
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
114+
resource.TestCheckResourceAttr(resourceName, "value", "W123"),
115+
116+
func(s *terraform.State) (err error) {
117+
resId, err = fromInstanceState(s, resourceName, "id")
118+
return err
119+
},
120+
),
121+
},
122+
94123
// verify updates to updatable parameters
95124
{
96125
Config: config + compartmentIdVariableStr + TagDefaultResourceDependencies +
97126
generateResourceFromRepresentationMap("oci_identity_tag_default", "test_tag_default", Optional, Update, tagDefaultRepresentation),
98127
Check: resource.ComposeAggregateTestCheckFunc(
99128
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
100129
resource.TestCheckResourceAttrSet(resourceName, "id"),
130+
resource.TestCheckResourceAttr(resourceName, "is_required", "false"),
101131
resource.TestCheckResourceAttrSet(resourceName, "tag_definition_id"),
102132
resource.TestCheckResourceAttrSet(resourceName, "tag_definition_name"),
103133
resource.TestCheckResourceAttrSet(resourceName, "tag_namespace_id"),
@@ -181,6 +211,7 @@ func TestIdentityTagDefaultResource_basic(t *testing.T) {
181211

182212
resource.TestCheckResourceAttr(singularDatasourceName, "compartment_id", compartmentId),
183213
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
214+
resource.TestCheckResourceAttr(singularDatasourceName, "is_required", "false"),
184215
resource.TestCheckResourceAttrSet(singularDatasourceName, "tag_definition_name"),
185216
resource.TestCheckResourceAttrSet(singularDatasourceName, "tag_namespace_id"),
186217
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),

oci/identity_tag_defaults_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ func (s *IdentityTagDefaultsDataSourceCrud) SetData() error {
121121
tagDefault["id"] = *r.Id
122122
}
123123

124+
if r.IsRequired != nil {
125+
tagDefault["is_required"] = *r.IsRequired
126+
}
127+
124128
tagDefault["state"] = r.LifecycleState
125129

126130
if r.TagDefinitionId != nil {

oci/identity_tag_resource_test.go

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"strconv"
55
"testing"
66

7-
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
8-
97
"github.com/hashicorp/terraform/helper/resource"
108
"github.com/hashicorp/terraform/terraform"
9+
10+
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
1111
)
1212

1313
var (
@@ -97,3 +97,92 @@ func TestIdentityTagDeletion(t *testing.T) {
9797
},
9898
})
9999
}
100+
101+
// execute this test in identity compartment only and not on root compartment
102+
func TestResourceIdentityDefaultTag_required(t *testing.T) {
103+
httpreplay.SetScenario("TestResourceIdentityDefaultTag_required")
104+
defer httpreplay.SaveScenario()
105+
106+
provider := testAccProvider
107+
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
108+
109+
config := legacyTestProviderConfig() + `
110+
variable defined_tag_namespace_name { default = "" }
111+
resource "oci_identity_tag_namespace" "tag-namespace1" {
112+
#Required
113+
compartment_id = "${var.compartment_id}"
114+
description = "Just a test"
115+
name = "example-tag-default-namespace"
116+
117+
is_retired = false
118+
}
119+
resource "oci_identity_tag" "tag1" {
120+
#Required
121+
description = "tf example tag 2"
122+
name = "tf-example-tag-default"
123+
tag_namespace_id = "${oci_identity_tag_namespace.tag-namespace1.id}"
124+
125+
is_retired = false
126+
}
127+
`
128+
129+
resourceName := "oci_identity_tag_default.test_tag_default"
130+
resource.Test(t, resource.TestCase{
131+
PreCheck: func() { testAccPreCheck(t) },
132+
Providers: map[string]terraform.ResourceProvider{
133+
"oci": provider,
134+
},
135+
Steps: []resource.TestStep{
136+
{
137+
Config: config +
138+
`
139+
resource "oci_identity_tag_default" "test_tag_default" {
140+
compartment_id = "${var.compartment_id}"
141+
is_required = "true"
142+
value="W123"
143+
tag_definition_id = "${oci_identity_tag.tag1.id}"
144+
}
145+
resource "oci_identity_tag_namespace" "tag-namespace-test-1" {
146+
compartment_id = "${var.compartment_id}"
147+
description = "test namespace 1"
148+
name = "example-test-delete-default-namespace-1"
149+
150+
defined_tags = "${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "${oci_identity_tag_default.test_tag_default.value}")}"
151+
is_retired = false
152+
}`,
153+
Check: resource.ComposeAggregateTestCheckFunc(
154+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
155+
resource.TestCheckResourceAttrSet(resourceName, "tag_definition_id"),
156+
resource.TestCheckResourceAttr(resourceName, "value", "W123"),
157+
// stream
158+
resource.TestCheckResourceAttr("oci_identity_tag_namespace.tag-namespace-test-1", "compartment_id", compartmentId),
159+
),
160+
},
161+
{
162+
Config: config +
163+
`
164+
resource "oci_identity_tag_default" "test_tag_default" {
165+
compartment_id = "${var.compartment_id}"
166+
is_required = "false"
167+
value="W123"
168+
tag_definition_id = "${oci_identity_tag.tag1.id}"
169+
}
170+
resource "oci_identity_tag_namespace" "tag-namespace-test-2" {
171+
compartment_id = "${var.compartment_id}"
172+
description = "test namespace 2"
173+
name = "example-test-delete-default-namespace-2"
174+
175+
is_retired = false
176+
}
177+
`,
178+
Check: resource.ComposeAggregateTestCheckFunc(
179+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
180+
resource.TestCheckResourceAttrSet(resourceName, "tag_definition_id"),
181+
resource.TestCheckResourceAttr(resourceName, "value", "W123"),
182+
// stream
183+
resource.TestCheckResourceAttr("oci_identity_tag_namespace.tag-namespace-test-2", "compartment_id", compartmentId),
184+
),
185+
},
186+
},
187+
})
188+
}

website/docs/d/identity_cost_tracking_tags.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The following attributes are exported:
4747
* `is_cost_tracking` - Indicates whether the tag is enabled for cost tracking.
4848
* `is_retired` - Indicates whether the tag is retired. See [Retiring Key Definitions and Namespace Definitions](https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/taggingoverview.htm#Retiring).
4949
* `name` - The name of the tag. The name must be unique across all tags in the namespace and can't be changed.
50-
* `state` - The tag's current state. After creating a tag, make sure its `lifecycleState` is ACTIVE before using it. After retiring a tag, make sure its `lifecycleState` is INACTIVE before using it.
50+
* `state` - The tag's current state. After creating a tag, make sure its `lifecycleState` is ACTIVE before using it. After retiring a tag, make sure its `lifecycleState` is INACTIVE before using it. If you delete a tag, you cannot delete another tag until the deleted tag's `lifecycleState` changes from DELETING to DELETED.
5151
* `tag_namespace_id` - The OCID of the namespace that contains the tag definition.
5252
* `tag_namespace_name` - The name of the tag namespace that contains the tag definition.
5353
* `time_created` - Date and time the tag was created, in the format defined by RFC3339. Example: `2016-08-25T21:10:29.600Z`

website/docs/d/identity_region_subscriptions.html.markdown

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,19 @@ The following attributes are exported:
4444
* `PHX`
4545
* `IAD`
4646
* `FRA`
47-
* `LHR`
47+
* `LHR`
48+
* `YYZ`
49+
* `NRT`
50+
* `ICN`
4851
* `region_name` - The region's name.
4952

5053
Allowed values are:
5154
* `us-phoenix-1`
5255
* `us-ashburn-1`
5356
* `eu-frankurt-1`
54-
* `uk-london-1`
57+
* `uk-london-1`
58+
* `ap-seoul-1`
59+
* `ap-tokyo-1`
60+
* `ca-toronto-1`
5561
* `state` - The region subscription state.
5662

website/docs/d/identity_regions.html.markdown

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ The following attributes are exported:
4040
* `PHX`
4141
* `IAD`
4242
* `FRA`
43-
* `LHR`
43+
* `LHR`
44+
* `YYZ`
45+
* `NRT`
46+
* `ICN`
4447
* `name` - The name of the region.
4548

4649
Allowed values are:
47-
* `us-phoenix-1`
50+
* `ap-seoul-1`
51+
* `ap-tokyo-1`
52+
* `ca-toronto-1`
53+
* `eu-frankurt-1`
54+
* `uk-london-1`
4855
* `us-ashburn-1`
49-
* `eu-frankfurt-1`
50-
* `uk-london-1`
56+
* `us-phoenix-1`
5157

website/docs/d/identity_tag_default.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ The following attributes are exported:
3434

3535
* `compartment_id` - The OCID of the compartment. The tag default applies to all new resources that get created in the compartment. Resources that existed before the tag default was created are not tagged.
3636
* `id` - The OCID of the tag default.
37+
* `is_required` - If you specify that a value is required, a value is set during resource creation (either by the user creating the resource or another tag defualt). If no value is set, resource creation is blocked.
38+
* If the `isRequired` flag is set to "true", the value is set during resource creation.
39+
* If the `isRequired` flag is set to "false", the value you enter is set during resource creation.
40+
41+
Example: `false`
3742
* `state` - The tag default's current state. After creating a `TagDefault`, make sure its `lifecycleState` is ACTIVE before using it.
3843
* `tag_definition_id` - The OCID of the tag definition. The tag default will always assign a default value for this tag definition.
3944
* `tag_definition_name` - The name used in the tag definition. This field is informational in the context of the tag default.

0 commit comments

Comments
 (0)