hashicorp / terraform-provider-awscc

Terraform AWS Cloud Control provider
https://registry.terraform.io/providers/hashicorp/awscc/latest/docs
Mozilla Public License 2.0
261 stars 120 forks source link

Resource `awscc_apprunner_service` non-mandatory attributes forcing replacement on update #815

Open AdrianBegg opened 1 year ago

AdrianBegg commented 1 year ago

Community Note

Terraform CLI and Terraform AWS Cloud Control Provider Version

Terraform v1.3.5 on windows_amd64

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

resource "awscc_apprunner_service" "example" {
  service_name                   = "example"
  auto_scaling_configuration_arn = aws_apprunner_auto_scaling_configuration_version.example.arn

  instance_configuration = {
    cpu    = 1024
    memory = 2048
  }

  observability_configuration = {
    observability_configuration_arn = awscc_apprunner_observability_configuration.example.observability_configuration_arn
    observability_enabled           = true
  }

  source_configuration = {
    auto_deployments_enabled = true

    authentication_configuration = {
      access_role_arn = aws_iam_role.example.arn
    }

    image_repository = {
      image_repository_type = "ECR"
      image_identifier      = "${aws_ecr_repository.example.repository_url}:latest"
      image_configuration = {
        port = 8080
      }
    }
  }

  network_configuration = {
    egress_configuration = {
      egress_type       = "VPC"
      vpc_connector_arn = awscc_apprunner_vpc_connector.example.vpc_connector_arn
    }
    ingress_configuration = {
      is_publicly_accessible = true 
    }
  }
}

Debug Output

Panic Output

Expected Behavior

During terraform apply (after initial resource deployment) as no changes have been made since the last apply the resource should remain outside of the plan.

Actual Behavior

The resource is marked as forced replacement. The triggering attributes are encryption_configuration.kms_key and tags.

  # awscc_apprunner_service.example must be replaced
-/+ resource "awscc_apprunner_service" "example" {
      + encryption_configuration       = { # forces replacement
          + kms_key = (known after apply)
        } -> (known after apply)
      + tags                           = [ # forces replacement
        ]
        # (4 unchanged attributes hidden)
    }

The expected behavior would be that; a) A tag update would not force a redeploy and; b) If encryption_configuration is not defined in the configuration and during read API returned no KMS defined that this would be ignored/not included in the plan

Steps to Reproduce

  1. terraform apply

Important Factoids

References

breathingdust commented 1 year ago

Both: encryption_configuration and tags are defined in the CloudFormation schema as createOnlyProperties:

https://github.com/hashicorp/terraform-provider-awscc/blob/f8e493036f442d0afd885c227b519574aa7faeee/internal/service/cloudformation/schemas/AWS_AppRunner_Service.json#L474-L478

This means those attributes use the RequiresReplace plan modifier so will result in a redeploy if modified (which they are not).

Note that tags is also considered a writeOnlyProperty

https://github.com/hashicorp/terraform-provider-awscc/blob/f8e493036f442d0afd885c227b519574aa7faeee/internal/service/cloudformation/schemas/AWS_AppRunner_Service.json#L485-L488