diff --git a/.changelog/44964.txt b/.changelog/44964.txt new file mode 100644 index 000000000000..9daba322ea9f --- /dev/null +++ b/.changelog/44964.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/aws_datazone_domain: Add `root_domain_unit_id` attribute +``` + +```release-note:enhancement +data-source/aws_datazone_domain: Add `root_domain_unit_id` attribute +``` diff --git a/internal/service/datazone/domain.go b/internal/service/datazone/domain.go index 491388fdd100..031cd2efffba 100644 --- a/internal/service/datazone/domain.go +++ b/internal/service/datazone/domain.go @@ -90,6 +90,12 @@ func (r *domainResource) Schema(ctx context.Context, request resource.SchemaRequ stringplanmodifier.UseStateForUnknown(), }, }, + "root_domain_unit_id": schema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, names.AttrServiceRole: schema.StringAttribute{ CustomType: fwtypes.ARNType, Optional: true, @@ -187,6 +193,16 @@ func (r *domainResource) Create(ctx context.Context, request resource.CreateRequ return } + // CreateDomain does not return root_domain_unit_id. + // It must be retrieved via GetDomain. + domain, err := findDomainByID(ctx, conn, data.ID.ValueString()) + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("reading DataZone Domain (%s)", data.ID.ValueString()), err.Error()) + + return + } + data.RootDomainUnitId = fwflex.StringToFramework(ctx, domain.RootDomainUnitId) + response.Diagnostics.Append(response.State.Set(ctx, data)...) } @@ -385,6 +401,7 @@ type domainResourceModel struct { KMSKeyIdentifier fwtypes.ARN `tfsdk:"kms_key_identifier"` Name types.String `tfsdk:"name"` PortalURL types.String `tfsdk:"portal_url"` + RootDomainUnitId types.String `tfsdk:"root_domain_unit_id"` ServiceRole fwtypes.ARN `tfsdk:"service_role"` SkipDeletionCheck types.Bool `tfsdk:"skip_deletion_check"` SingleSignOn fwtypes.ListNestedObjectValueOf[singleSignOnModel] `tfsdk:"single_sign_on"` diff --git a/internal/service/datazone/domain_data_source.go b/internal/service/datazone/domain_data_source.go index a2933c7d5dd3..dbddae39d1b7 100644 --- a/internal/service/datazone/domain_data_source.go +++ b/internal/service/datazone/domain_data_source.go @@ -65,6 +65,9 @@ func (d *domainDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, Optional: true, Computed: true, }, + "root_domain_unit_id": schema.StringAttribute{ + Computed: true, + }, "portal_url": schema.StringAttribute{ Computed: true, }, @@ -124,13 +127,21 @@ func (d *domainDataSource) ConfigValidators(_ context.Context) []datasource.Conf } } -func findDomain(ctx context.Context, conn *datazone.Client, filter tfslices.Predicate[*awstypes.DomainSummary]) (*awstypes.DomainSummary, error) { +func findDomain(ctx context.Context, conn *datazone.Client, filter tfslices.Predicate[*awstypes.DomainSummary]) (*datazone.GetDomainOutput, error) { domain, err := findDomains(ctx, conn, filter) if err != nil { return nil, err } - return tfresource.AssertSingleValueResult(domain) + domain1, err := tfresource.AssertSingleValueResult(domain) + if err != nil { + return nil, err + } + output, err := findDomainByID(ctx, conn, aws.ToString(domain1.Id)) + if err != nil { + return nil, err + } + return output, nil } func findDomains(ctx context.Context, conn *datazone.Client, filter tfslices.Predicate[*awstypes.DomainSummary]) ([]awstypes.DomainSummary, error) { @@ -163,6 +174,7 @@ type domainDataSourceModel struct { LastUpdatedAt timetypes.RFC3339 `tfsdk:"last_updated_at"` ManagedAccountID types.String `tfsdk:"managed_account_id"` Name types.String `tfsdk:"name"` + RootDomainUnitID types.String `tfsdk:"root_domain_unit_id"` PortalURL types.String `tfsdk:"portal_url"` Status types.String `tfsdk:"status"` } diff --git a/internal/service/datazone/domain_data_source_test.go b/internal/service/datazone/domain_data_source_test.go index 22258fc996dd..58a226c2783b 100644 --- a/internal/service/datazone/domain_data_source_test.go +++ b/internal/service/datazone/domain_data_source_test.go @@ -30,6 +30,9 @@ func TestAccDataZoneDomainDataSource_basic(t *testing.T) { resource.TestCheckResourceAttrPair(dataSourceName, names.AttrARN, resourceName, names.AttrARN), resource.TestCheckResourceAttrPair(dataSourceName, names.AttrID, resourceName, names.AttrID), resource.TestCheckResourceAttrPair(dataSourceName, names.AttrName, resourceName, names.AttrName), + resource.TestCheckResourceAttrPair(dataSourceName, "root_domain_unit_id", resourceName, "root_domain_unit_id"), + resource.TestCheckResourceAttrPair(dataSourceName, "portal_url", resourceName, "portal_url"), + resource.TestCheckResourceAttrPair(dataSourceName, "domain_version", resourceName, "domain_version"), ), }, }, @@ -54,6 +57,7 @@ func TestAccDataZoneDomainDataSource_name(t *testing.T) { resource.TestCheckResourceAttrPair(dataSourceName, names.AttrARN, resourceName, names.AttrARN), resource.TestCheckResourceAttrPair(dataSourceName, names.AttrID, resourceName, names.AttrID), resource.TestCheckResourceAttrPair(dataSourceName, names.AttrName, resourceName, names.AttrName), + resource.TestCheckResourceAttrPair(dataSourceName, "root_domain_unit_id", resourceName, "root_domain_unit_id"), ), }, }, diff --git a/internal/service/datazone/domain_test.go b/internal/service/datazone/domain_test.go index 265e336bbe48..66d77248806c 100644 --- a/internal/service/datazone/domain_test.go +++ b/internal/service/datazone/domain_test.go @@ -44,6 +44,7 @@ func TestAccDataZoneDomain_basic(t *testing.T) { acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "datazone", "domain/{id}"), resource.TestCheckResourceAttr(resourceName, "domain_version", "V1"), resource.TestCheckNoResourceAttr(resourceName, names.AttrServiceRole), + resource.TestCheckResourceAttrSet(resourceName, "root_domain_unit_id"), ), }, { @@ -52,6 +53,20 @@ func TestAccDataZoneDomain_basic(t *testing.T) { ImportStateVerify: true, ImportStateVerifyIgnore: []string{names.AttrApplyImmediately, "user", "skip_deletion_check"}, }, + { + Config: testAccDomainConfig_description(rName, "test_description"), + Check: resource.ComposeTestCheckFunc( + testAccCheckDomainExists(ctx, resourceName, &domain), + resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), + resource.TestCheckResourceAttrSet(resourceName, "portal_url"), + resource.TestCheckResourceAttrSet(resourceName, names.AttrID), + acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "datazone", "domain/{id}"), + resource.TestCheckResourceAttr(resourceName, "domain_version", "V1"), + resource.TestCheckNoResourceAttr(resourceName, names.AttrServiceRole), + resource.TestCheckResourceAttrSet(resourceName, "root_domain_unit_id"), + resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "test_description"), + ), + }, }, }) } diff --git a/website/docs/d/datazone_domain.html.markdown b/website/docs/d/datazone_domain.html.markdown index feaa7c13653a..4a9ac38baafa 100644 --- a/website/docs/d/datazone_domain.html.markdown +++ b/website/docs/d/datazone_domain.html.markdown @@ -39,4 +39,5 @@ This data source exports the following attributes in addition to the arguments a * `last_updated_at` - The date and time the Domain was last updated. * `managed_account_id` - The AWS account ID that owns the Domain. * `portal_url` - URL of the Domain. +* `root_domain_unit_id` - ID of the root domain unit. * `status` - Status of the Domain. diff --git a/website/docs/r/datazone_domain.html.markdown b/website/docs/r/datazone_domain.html.markdown index a0ddac37bc99..0d829b1e3d51 100644 --- a/website/docs/r/datazone_domain.html.markdown +++ b/website/docs/r/datazone_domain.html.markdown @@ -172,6 +172,7 @@ This resource exports the following attributes in addition to the arguments abov * `arn` - ARN of the Domain. * `id` - ID of the Domain. * `portal_url` - URL of the data portal for the Domain. +* `root_domain_unit_id` - ID of the root domain unit. * `tags_all` - Map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). ## Timeouts