diff --git a/cf-custom-resources/lib/custom-domain-app-runner.js b/cf-custom-resources/lib/custom-domain-app-runner.js index 613c6430116..bbe0533c261 100644 --- a/cf-custom-resources/lib/custom-domain-app-runner.js +++ b/cf-custom-resources/lib/custom-domain-app-runner.js @@ -95,10 +95,7 @@ exports.handler = async function (event, context) { }), }); appRunnerClient = new AWS.AppRunner(); - appHostedZoneID = props.RootHostedZoneId - if (!appHostedZoneID){ - appHostedZoneID = await domainHostedZoneID(appDNSName); - } + appHostedZoneID = await domainHostedZoneID(appDNSName); switch (event.RequestType) { case "Create": case "Update": diff --git a/cf-custom-resources/lib/custom-domain.js b/cf-custom-resources/lib/custom-domain.js index 56eb6cf37d7..23a2ef81ef2 100644 --- a/cf-custom-resources/lib/custom-domain.js +++ b/cf-custom-resources/lib/custom-domain.js @@ -98,10 +98,7 @@ const writeCustomDomainRecord = async function ( accessDNS, accessHostedZone, aliasTypes, - action, - rootHostedZoneId, - appHostedZoneId, - envHostedZoneId + action ) { const actions = []; for (const alias of aliases) { @@ -114,8 +111,7 @@ const writeCustomDomainRecord = async function ( accessDNS, accessHostedZone, aliasType.domain, - action, - envHostedZoneId + action )); break; case aliasTypes.AppDomainZone: @@ -125,8 +121,7 @@ const writeCustomDomainRecord = async function ( accessDNS, accessHostedZone, aliasType.domain, - action, - appHostedZoneId + action )); break; case aliasTypes.RootDomainZone: @@ -136,8 +131,7 @@ const writeCustomDomainRecord = async function ( accessDNS, accessHostedZone, aliasType.domain, - action, - rootHostedZoneId + action )); break; // We'll skip if it is the other alias type since it will be in another account's route53. @@ -153,10 +147,9 @@ const writeARecord = async function ( accessDNS, accessHostedZone, domain, - action, - hostedZoneID + action ) { - let hostedZoneId = hostedZoneID || hostedZoneCache.get(domain); + let hostedZoneId = hostedZoneCache.get(domain); if (!hostedZoneId) { const hostedZones = await route53 .listHostedZonesByName({ @@ -240,9 +233,6 @@ exports.handler = async function (event, context) { props.PublicAccessHostedZone, aliasTypes, changeRecordAction.Upsert, - props.RootHostedZoneId, - props.AppHostedZoneId, - props.EnvHostedZoneId ); break; case "Update": @@ -254,9 +244,6 @@ exports.handler = async function (event, context) { props.PublicAccessHostedZone, aliasTypes, changeRecordAction.Upsert, - props.RootHostedZoneId, - props.AppHostedZoneId, - props.EnvHostedZoneId ); // After upserting new aliases, delete unused ones. For example: previously we have ["foo.com", "bar.com"], // and now the aliases param is updated to just ["foo.com"] then we'll delete "bar.com". @@ -274,9 +261,6 @@ exports.handler = async function (event, context) { props.PublicAccessHostedZone, aliasTypes, changeRecordAction.Delete, - props.RootHostedZoneId, - props.AppHostedZoneId, - props.EnvHostedZoneId ); break; case "Delete": @@ -287,10 +271,7 @@ exports.handler = async function (event, context) { props.PublicAccessDNS, props.PublicAccessHostedZone, aliasTypes, - changeRecordAction.Delete, - props.RootHostedZoneId, - props.AppHostedZoneId, - props.EnvHostedZoneId + changeRecordAction.Delete ); break; default: diff --git a/cf-custom-resources/lib/dns-cert-validator.js b/cf-custom-resources/lib/dns-cert-validator.js index ac1994805cf..5c2d980fff9 100644 --- a/cf-custom-resources/lib/dns-cert-validator.js +++ b/cf-custom-resources/lib/dns-cert-validator.js @@ -212,8 +212,6 @@ const validateCertificate = async function( options, envRoute53, appRoute53, - rootHostedZoneId, - appHostedZoneId, envHostedZoneId, certificateARN, acm @@ -223,8 +221,6 @@ const validateCertificate = async function( options, envRoute53, appRoute53, - rootHostedZoneId, - appHostedZoneId, envHostedZoneId ); @@ -245,9 +241,7 @@ const updateHostedZoneRecords = async function ( options, envRoute53, appRoute53, - rootHostedZoneId, - appHostedZoneId, - envHostedZoneId, + envHostedZoneId ) { const promises = []; for (const option of options) { @@ -271,7 +265,6 @@ const updateHostedZoneRecords = async function ( record: option.ResourceRecord, action: action, domainName: domainType.domain, - hostedZoneId: appHostedZoneId, }) ); break; @@ -282,7 +275,6 @@ const updateHostedZoneRecords = async function ( record: option.ResourceRecord, action: action, domainName: domainType.domain, - hostedZoneId: rootHostedZoneId, }) ); break; @@ -301,8 +293,6 @@ const deleteHostedZoneRecords = async function ( envRoute53, appRoute53, acm, - rootHostedZoneId, - appHostedZoneId, envHostedZoneId ) { let listCertificatesInput = {}; @@ -364,8 +354,6 @@ const deleteHostedZoneRecords = async function ( filteredRecordOption, envRoute53, appRoute53, - rootHostedZoneId, - appHostedZoneId, envHostedZoneId ); } catch (e) { @@ -428,8 +416,6 @@ const deleteCertificate = async function ( arn, certDomain, region, - rootHostedZoneId, - appHostedZoneId, envHostedZoneId, rootDnsRole ) { @@ -477,8 +463,6 @@ const deleteCertificate = async function ( envRoute53, appRoute53, acm, - rootHostedZoneId, - appHostedZoneId, envHostedZoneId ); @@ -642,7 +626,7 @@ exports.certificateRequestHandler = async function (event, context) { ); responseData.Arn = physicalResourceId = response.CertificateArn; // Set physicalResourceId as soon as we can. options = await waitForValidationOptionsToBeReady(response.CertificateArn, sansToUse, acm); - await validateCertificate(options, envRoute53, appRoute53, props.RootHostedZoneId, props.AppHostedZoneId, props.EnvHostedZoneId, response.CertificateArn, acm); + await validateCertificate(options, envRoute53, appRoute53, props.EnvHostedZoneId, response.CertificateArn, acm); break; case "Update": // Exit early if cert doesn't change. @@ -660,7 +644,7 @@ exports.certificateRequestHandler = async function (event, context) { ); responseData.Arn = physicalResourceId = response.CertificateArn; options = await waitForValidationOptionsToBeReady(response.CertificateArn, sansToUse, acm); - await validateCertificate(options, envRoute53, appRoute53, props.RootHostedZoneId, props.AppHostedZoneId, props.EnvHostedZoneId, response.CertificateArn, acm); + await validateCertificate(options, envRoute53, appRoute53, props.EnvHostedZoneId, response.CertificateArn, acm); break; case "Delete": // If the resource didn't create correctly, the physical resource ID won't be the @@ -670,8 +654,6 @@ exports.certificateRequestHandler = async function (event, context) { physicalResourceId, certDomain, props.Region, - props.RootHostedZoneId, - props.AppHostedZoneId, props.EnvHostedZoneId, props.RootDNSRole ); diff --git a/cf-custom-resources/lib/dns-delegation.js b/cf-custom-resources/lib/dns-delegation.js index 1bd7abf981c..5bbe12eca1b 100644 --- a/cf-custom-resources/lib/dns-delegation.js +++ b/cf-custom-resources/lib/dns-delegation.js @@ -90,8 +90,7 @@ const createSubdomainInRoot = async function ( domainName, subDomain, nameServers, - rootDnsRole, - hostedZoneId + rootDnsRole ) { const route53 = new aws.Route53({ credentials: new aws.ChainableTemporaryCredentials({ @@ -99,7 +98,7 @@ const createSubdomainInRoot = async function ( masterCredentials: new aws.EnvironmentCredentials("AWS"), }), }); - if (!hostedZoneId) { + const hostedZones = await route53 .listHostedZonesByName({ DNSName: domainName, @@ -116,8 +115,8 @@ const createSubdomainInRoot = async function ( // HostedZoneIDs are of the form /hostedzone/1234455, but the actual // ID is after the last slash. - hostedZoneId = domainHostedZone.Id.split("/").pop(); - } + const hostedZoneId = domainHostedZone.Id.split("/").pop(); + const changeBatch = await route53 .changeResourceRecordSets({ ChangeBatch: { @@ -159,8 +158,7 @@ const deleteSubdomainInRoot = async function ( requestId, domainName, subDomain, - rootDnsRole, - hostedZoneId + rootDnsRole ) { const route53 = new aws.Route53({ credentials: new aws.ChainableTemporaryCredentials({ @@ -168,7 +166,7 @@ const deleteSubdomainInRoot = async function ( masterCredentials: new aws.EnvironmentCredentials("AWS"), }), }); - if (!hostedZoneId) { + const hostedZones = await route53 .listHostedZonesByName({ DNSName: domainName, @@ -185,8 +183,8 @@ const deleteSubdomainInRoot = async function ( // HostedZoneIDs are of the form /hostedzone/1234455, but the actual // ID is after the last slash. - hostedZoneId = domainHostedZone.Id.split("/").pop(); - } + const hostedZoneId = domainHostedZone.Id.split("/").pop(); + // Find the recordsets for this subdomain, and then remove it // from the hosted zone. const recordSets = await route53 @@ -277,8 +275,7 @@ exports.domainDelegationHandler = async function (event, context) { props.DomainName, props.SubdomainName, props.NameServers, - props.RootDNSRole, - props.RootHostedZoneId + props.RootDNSRole ); break; case "Delete": @@ -286,8 +283,7 @@ exports.domainDelegationHandler = async function (event, context) { event.RequestId, props.DomainName, props.SubdomainName, - props.RootDNSRole, - props.RootHostedZoneId + props.RootDNSRole ); break; default: diff --git a/cf-custom-resources/lib/wkld-cert-validator.js b/cf-custom-resources/lib/wkld-cert-validator.js index 138b5fa8e46..52f38dd802a 100644 --- a/cf-custom-resources/lib/wkld-cert-validator.js +++ b/cf-custom-resources/lib/wkld-cert-validator.js @@ -10,7 +10,7 @@ const ATTEMPTS_CERTIFICATE_VALIDATED = 19; const ATTEMPTS_CERTIFICATE_NOT_IN_USE = 12; const DELAY_CERTIFICATE_VALIDATED_IN_S = 30; -let rootHostedZoneID,appHostedZoneID,envHostedZoneID, appName, envName, serviceName, certificateDomain, domainTypes, rootDNSRole, domainName, isCloudFrontCert; +let envHostedZoneID, appName, envName, serviceName, certificateDomain, domainTypes, rootDNSRole, domainName, isCloudFrontCert; let defaultSleep = function (ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }; @@ -168,8 +168,6 @@ exports.handler = async function (event, context) { const aliases = new Set(props.Aliases); // Initialize global variables. - rootHostedZoneID = props.RootHostedZoneId; - appHostedZoneID = props.AppHostedZoneId; envHostedZoneID = props.EnvHostedZoneId; envName = props.EnvName; appName = props.AppName; @@ -750,23 +748,17 @@ async function domainResources(alias) { }; } if (domainTypes.AppDomainZone.regex.test(alias)) { - if (!appHostedZoneID){ - appHostedZoneID = await hostedZoneID.app() - } return { domain: domainTypes.AppDomainZone.domain, route53Client: clients.app.route53(), - hostedZoneID: appHostedZoneID, + hostedZoneID: await hostedZoneID.app(), }; } if (domainTypes.RootDomainZone.regex.test(alias)) { - if (!rootHostedZoneID){ - rootHostedZoneID = await hostedZoneID.root() - } return { domain: domainTypes.RootDomainZone.domain, route53Client: clients.root.route53(), - hostedZoneID: rootHostedZoneID, + hostedZoneID: await hostedZoneID.root(), }; } throw new UnrecognizedDomainTypeError(`unrecognized domain type for ${alias}`); diff --git a/cf-custom-resources/lib/wkld-custom-domain.js b/cf-custom-resources/lib/wkld-custom-domain.js index 88d415906de..2b0736b7389 100644 --- a/cf-custom-resources/lib/wkld-custom-domain.js +++ b/cf-custom-resources/lib/wkld-custom-domain.js @@ -6,7 +6,7 @@ const ATTEMPTS_VALIDATION_OPTIONS_READY = 10; const ATTEMPTS_RECORD_SETS_CHANGE = 10; const DELAY_RECORD_SETS_CHANGE_IN_S = 30; -let rootHostedZoneID,appHostedZoneID,envHostedZoneID, appName, envName, serviceName, domainTypes, rootDNSRole, domainName; +let envHostedZoneID, appName, envName, serviceName, domainTypes, rootDNSRole, domainName; let defaultSleep = function (ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }; @@ -157,8 +157,6 @@ exports.handler = async function (event, context) { const aliases = new Set(props.Aliases); // Initialize global variables. - rootHostedZoneID = props.RootHostedZoneId; - appHostedZoneID = props.AppHostedZoneId; envHostedZoneID = props.EnvHostedZoneId; envName = props.EnvName; appName = props.AppName; @@ -446,23 +444,17 @@ async function domainResources(alias) { }; } if (domainTypes.AppDomainZone.regex.test(alias)) { - if (!appHostedZoneID){ - appHostedZoneID = await hostedZoneID.app() - } return { domain: domainTypes.AppDomainZone.domain, route53Client: clients.app.route53(), - hostedZoneID: appHostedZoneID, + hostedZoneID: await hostedZoneID.app(), }; } if (domainTypes.RootDomainZone.regex.test(alias)) { - if (!rootHostedZoneID){ - rootHostedZoneID = await hostedZoneID.root() - } return { domain: domainTypes.RootDomainZone.domain, route53Client: clients.root.route53(), - hostedZoneID: rootHostedZoneID, + hostedZoneID: await hostedZoneID.root(), }; } throw new UnrecognizedDomainTypeError(`unrecognized domain type for ${alias}`); diff --git a/cf-custom-resources/test/custom-domain-app-runner-test.js b/cf-custom-resources/test/custom-domain-app-runner-test.js index 90f3a6875e7..783dfeb7ab1 100644 --- a/cf-custom-resources/test/custom-domain-app-runner-test.js +++ b/cf-custom-resources/test/custom-domain-app-runner-test.js @@ -13,8 +13,8 @@ const nock = require("nock"); let origLog = console.log; describe("Custom Domain for App Runner Service", () => { - const [mockServiceARN, mockCustomDomain, mockHostedZoneID, mockResponseURL, mockPhysicalResourceID, mockLogicalResourceID, mockTarget, mockAppDNSName,mockAppHostedZoneID] = - ["mockService", "mockDomain", "mockHostedZoneID", "https://mock.com/", "mockPhysicalResourceID", "mockLogicalResourceID", "mockTarget", "mockAppDNSName","Z00ABC" ]; + const [mockServiceARN, mockCustomDomain, mockHostedZoneID, mockResponseURL, mockPhysicalResourceID, mockLogicalResourceID, mockTarget, mockAppDNSName] = + ["mockService", "mockDomain", "mockHostedZoneID", "https://mock.com/", "mockPhysicalResourceID", "mockLogicalResourceID", "mockTarget", "mockAppDNSName", ]; beforeEach(() => { // Prevent logging. @@ -635,6 +635,13 @@ describe("Custom Domain for App Runner Service", () => { test("success", () => { const mockTarget = "mockTarget"; + const mockListHostedZonesByName = sinon.fake.resolves({ + HostedZones: [ + { + Id: "/hostedzone/mockHostedZoneID", + }, + ], + }); // Able to retrieve the hosted zone ID. const mockAssociateCustomDomain = sinon.fake.resolves({DNSTarget: mockTarget,}); const mockWaitFor = sinon.fake.resolves(); const mockDescribeCustomDomains = sinon.stub(); @@ -682,6 +689,7 @@ describe("Custom Domain for App Runner Service", () => { AWS.mock("Route53", "changeResourceRecordSets", mockChangeResourceRecordSets); AWS.mock("Route53", "waitFor", mockWaitFor); AWS.mock("AppRunner", "describeCustomDomains", mockDescribeCustomDomains); + AWS.mock("Route53", "listHostedZonesByName", mockListHostedZonesByName); const expectedResponse = nock(mockResponseURL) .put("/", (body) => { @@ -697,7 +705,6 @@ describe("Custom Domain for App Runner Service", () => { ServiceARN: mockServiceARN, AppDNSRole: "", CustomDomain: mockCustomDomain, - RootHostedZoneId: mockAppHostedZoneID, }, PhysicalResourceId: mockPhysicalResourceID, LogicalResourceId: mockLogicalResourceID, diff --git a/cf-custom-resources/test/custom-domain-test.js b/cf-custom-resources/test/custom-domain-test.js index 5c1aa1af3f9..341e40a57eb 100644 --- a/cf-custom-resources/test/custom-domain-test.js +++ b/cf-custom-resources/test/custom-domain-test.js @@ -17,16 +17,12 @@ describe("DNS Validated Certificate Handler", () => { const testEnvName = "test"; const testDomainName = "example.com"; const testAliases = `{"frontend": ["v1.${testEnvName}.${testAppName}.${testDomainName}", "foobar.com"]}`; - const testAliases2 = `{"frontend": ["v2.${testEnvName}.${testAppName}.${testDomainName}", "foobar.com"]}`; const testUpdatedAliases = `{"frontend": ["v2.${testEnvName}.${testAppName}.${testDomainName}", "foobar.com"]}`; const testAccessDNS = "examp-publi-gsedbvf8t12c-852245110.us-west-1.elb.amazonaws.com."; const testLBHostedZone = "Z1H1FL5HABSF5"; const testHostedZoneId = "Z3P5QSUBK4POTI"; const testRootDNSRole = "mockRole"; - const mockRootHostedZoneId = "Z00ABC" - const mockAppHostedZoneID = "Z00DEF" - const mockEnvHostedZoneID = "Z00GHI" beforeEach(() => { handler.withDefaultResponseURL(ResponseURL); @@ -246,68 +242,6 @@ describe("DNS Validated Certificate Handler", () => { }); }); - test("Create success with out listhostedzones api call", () => { - const changeResourceRecordSetsFake = sinon.fake.resolves({ - ChangeInfo: { - Id: "bogus", - }, - }); - - AWS.mock( - "Route53", - "changeResourceRecordSets", - changeResourceRecordSetsFake - ); - - const request = nock(ResponseURL) - .put("/", (body) => { - return body.Status === "SUCCESS"; - }) - .reply(200); - return LambdaTester(handler.handler) - .event({ - RequestType: "Create", - ResourceProperties: { - AppName: testAppName, - EnvName: testEnvName, - DomainName: testDomainName, - Aliases: testAliases2, - Region: "us-east-1", - PublicAccessDNS: testAccessDNS, - PublicAccessHostedZone: testLBHostedZone, - AppDNSRole: testRootDNSRole, - RootHostedZoneId: mockRootHostedZoneId, - AppHostedZoneId:mockAppHostedZoneID, - EnvHostedZoneId: mockEnvHostedZoneID, - }, - }) - .expectResolve(() => { - sinon.assert.calledWith( - changeResourceRecordSetsFake, - sinon.match({ - ChangeBatch: { - Changes: [ - { - Action: "UPSERT", - ResourceRecordSet: { - Name: `v2.${testEnvName}.${testAppName}.${testDomainName}`, - Type: "A", - AliasTarget: { - HostedZoneId: testLBHostedZone, - DNSName: testAccessDNS, - EvaluateTargetHealth: true, - }, - }, - }, - ], - }, - HostedZoneId: mockEnvHostedZoneID, - }) - ); - expect(request.isDone()).toBe(true); - }); - }); - test("Update success", () => { const changeResourceRecordSetsFake = sinon.fake.resolves({ ChangeInfo: { diff --git a/internal/pkg/cli/deploy/env.go b/internal/pkg/cli/deploy/env.go index 5e9f5baf06d..d9239d81f68 100644 --- a/internal/pkg/cli/deploy/env.go +++ b/internal/pkg/cli/deploy/env.go @@ -20,7 +20,6 @@ import ( "github.com/aws/copilot-cli/internal/pkg/aws/ec2" "github.com/aws/copilot-cli/internal/pkg/aws/elbv2" "github.com/aws/copilot-cli/internal/pkg/aws/partitions" - "github.com/aws/copilot-cli/internal/pkg/aws/route53" awss3 "github.com/aws/copilot-cli/internal/pkg/aws/s3" "github.com/aws/copilot-cli/internal/pkg/aws/sessions" "github.com/aws/copilot-cli/internal/pkg/cli/deploy/patch" @@ -79,9 +78,6 @@ type stackDescriber interface { Resources() ([]*stack.Resource, error) } -type domainHostedZoneGetter interface { - PublicDomainHostedZoneID(domainName string) (string, error) -} type envDeployer struct { app *config.Application env *config.Environment @@ -100,7 +96,6 @@ type envDeployer struct { envDescriber envDescriber lbDescriber lbDescriber newServiceStackDescriber func(string) stackDescriber - domainHostedZoneGetter domainHostedZoneGetter // Dependencies for parsing addons. ws WorkspaceAddonsReaderPathGetter @@ -178,8 +173,7 @@ func NewEnvDeployer(in *NewEnvDeployerInput) (*envDeployer, error) { parseAddons: sync.OnceValues(func() (stackBuilder, error) { return addon.ParseFromEnv(in.Workspace) }), - ws: in.Workspace, - domainHostedZoneGetter: route53.New(defaultSession), + ws: in.Workspace, } return deployer, nil } @@ -404,21 +398,12 @@ func (d *envDeployer) buildStackInput(in *DeployEnvironmentInput) (*cfnstack.Env if err != nil { return nil, err } - var appHostedZoneID string - if d.app.Domain != "" { - appHostedZoneID, err = appDomainHostedZoneId(d.app.Name, d.app.Domain, d.domainHostedZoneGetter) - if err != nil { - return nil, err - } - } return &cfnstack.EnvConfig{ Name: d.env.Name, App: deploy.AppInformation{ - Name: d.app.Name, - Domain: d.app.Domain, - AccountPrincipalARN: in.RootUserARN, - RootDomainHostedZoneId: d.app.DomainHostedZoneID, - AppDomainHostedZoneId: appHostedZoneID, + Name: d.app.Name, + Domain: d.app.Domain, + AccountPrincipalARN: in.RootUserARN, }, AdditionalTags: d.app.Tags, Addons: addons, @@ -597,14 +582,3 @@ func (d *envDeployer) cfManagedPrefixListID() (string, error) { return id, nil } - -func appDomainHostedZoneId(appName, domain string, domainHostedZoneGetter domainHostedZoneGetter) (string, error) { - if domain == "" { - return "", nil - } - appHostedZoneID, err := domainHostedZoneGetter.PublicDomainHostedZoneID(fmt.Sprintf("%s.%s", appName, domain)) - if err != nil { - return "", fmt.Errorf("get public public hosted zone ID for domain %s: %w", fmt.Sprintf("%s.%s", appName, domain), err) - } - return appHostedZoneID, nil -} diff --git a/internal/pkg/cli/deploy/env_test.go b/internal/pkg/cli/deploy/env_test.go index 9fa0b56ef1e..ea656a6d416 100644 --- a/internal/pkg/cli/deploy/env_test.go +++ b/internal/pkg/cli/deploy/env_test.go @@ -44,9 +44,8 @@ type envDeployerMocks struct { stackDescribers map[string]*mocks.MockstackDescriber ws *mocks.MockWorkspaceAddonsReaderPathGetter - parseAddons func() (stackBuilder, error) - addons *mocks.MockstackBuilder - domainHostedZoneGetter *mocks.MockdomainHostedZoneGetter + parseAddons func() (stackBuilder, error) + addons *mocks.MockstackBuilder } func TestEnvDeployer_UploadArtifacts(t *testing.T) { @@ -395,9 +394,7 @@ func TestEnvDeployer_GenerateCloudFormationTemplate(t *testing.T) { ) mockError := errors.New("some error") mockApp := &config.Application{ - Name: mockAppName, - Domain: "example.com", - DomainHostedZoneID: "v1.example.com", + Name: mockAppName, } testCases := map[string]struct { inManifest manifest.Environment @@ -422,7 +419,6 @@ func TestEnvDeployer_GenerateCloudFormationTemplate(t *testing.T) { m.parseAddons = func() (stackBuilder, error) { return nil, &addon.ErrAddonsNotFound{} } - m.domainHostedZoneGetter.EXPECT().PublicDomainHostedZoneID(fmt.Sprintf("%s.%s", mockAppName, mockApp.Domain)).Return("Z00ABC", nil) m.envDeployer.EXPECT().DeployedEnvironmentParameters(gomock.Any(), gomock.Any()).Return(nil, mockError) }, wantedError: errors.New("describe environment stack parameters: some error"), @@ -437,7 +433,6 @@ func TestEnvDeployer_GenerateCloudFormationTemplate(t *testing.T) { } m.envDeployer.EXPECT().DeployedEnvironmentParameters(gomock.Any(), gomock.Any()).Return(nil, nil) m.envDeployer.EXPECT().ForceUpdateOutputID(gomock.Any(), gomock.Any()).Return("", mockError) - m.domainHostedZoneGetter.EXPECT().PublicDomainHostedZoneID(fmt.Sprintf("%s.%s", mockAppName, mockApp.Domain)).Return("Z00ABC", nil) }, wantedError: errors.New("retrieve environment stack force update ID: some error"), }, @@ -452,7 +447,6 @@ func TestEnvDeployer_GenerateCloudFormationTemplate(t *testing.T) { m.envDeployer.EXPECT().DeployedEnvironmentParameters(gomock.Any(), gomock.Any()).Return(nil, nil) m.envDeployer.EXPECT().ForceUpdateOutputID(gomock.Any(), gomock.Any()).Return("", nil) m.stackSerializer.EXPECT().Template().Return("", mockError) - m.domainHostedZoneGetter.EXPECT().PublicDomainHostedZoneID(fmt.Sprintf("%s.%s", mockAppName, mockApp.Domain)).Return("Z00ABC", nil) }, wantedError: errors.New("generate stack template: some error"), }, @@ -468,7 +462,6 @@ func TestEnvDeployer_GenerateCloudFormationTemplate(t *testing.T) { m.envDeployer.EXPECT().ForceUpdateOutputID(gomock.Any(), gomock.Any()).Return("", nil) m.stackSerializer.EXPECT().Template().Return("", nil) m.stackSerializer.EXPECT().SerializedParameters().Return("", mockError) - m.domainHostedZoneGetter.EXPECT().PublicDomainHostedZoneID(fmt.Sprintf("%s.%s", mockAppName, mockApp.Domain)).Return("Z00ABC", nil) }, wantedError: errors.New("generate stack template parameters: some error"), }, @@ -508,7 +501,6 @@ func TestEnvDeployer_GenerateCloudFormationTemplate(t *testing.T) { m.envDeployer.EXPECT().ForceUpdateOutputID(gomock.Any(), gomock.Any()).Return("", nil) m.stackSerializer.EXPECT().Template().Return("aloo", nil) m.stackSerializer.EXPECT().SerializedParameters().Return("gobi", nil) - m.domainHostedZoneGetter.EXPECT().PublicDomainHostedZoneID(fmt.Sprintf("%s.%s", mockAppName, mockApp.Domain)).Return("Z00ABC", nil).Return("Z00ABC", nil) }, wantedTemplate: "aloo", @@ -528,7 +520,6 @@ func TestEnvDeployer_GenerateCloudFormationTemplate(t *testing.T) { m.envDeployer.EXPECT().ForceUpdateOutputID(gomock.Any(), gomock.Any()).Return("", nil) m.stackSerializer.EXPECT().Template().Return("aloo", nil) m.stackSerializer.EXPECT().SerializedParameters().Return("gobi", nil) - m.domainHostedZoneGetter.EXPECT().PublicDomainHostedZoneID(fmt.Sprintf("%s.%s", mockAppName, mockApp.Domain)).Return("Z00ABC", nil) }, wantedTemplate: "aloo", @@ -541,10 +532,9 @@ func TestEnvDeployer_GenerateCloudFormationTemplate(t *testing.T) { defer ctrl.Finish() m := &envDeployerMocks{ - appCFN: mocks.NewMockappResourcesGetter(ctrl), - envDeployer: mocks.NewMockenvironmentDeployer(ctrl), - stackSerializer: cfnmocks.NewMockStackConfiguration(ctrl), - domainHostedZoneGetter: mocks.NewMockdomainHostedZoneGetter(ctrl), + appCFN: mocks.NewMockappResourcesGetter(ctrl), + envDeployer: mocks.NewMockenvironmentDeployer(ctrl), + stackSerializer: cfnmocks.NewMockStackConfiguration(ctrl), } tc.setUpMocks(m, ctrl) d := envDeployer{ @@ -558,8 +548,7 @@ func TestEnvDeployer_GenerateCloudFormationTemplate(t *testing.T) { newStack: func(_ *cfnstack.EnvConfig, _ string, _ []*awscfn.Parameter) (cloudformation.StackConfiguration, error) { return m.stackSerializer, nil }, - parseAddons: m.parseAddons, - domainHostedZoneGetter: m.domainHostedZoneGetter, + parseAddons: m.parseAddons, } actual, err := d.GenerateCloudFormationTemplate(&DeployEnvironmentInput{ Manifest: &tc.inManifest, diff --git a/internal/pkg/cli/deploy/lbws.go b/internal/pkg/cli/deploy/lbws.go index 0814aa52c12..a31fac419ff 100644 --- a/internal/pkg/cli/deploy/lbws.go +++ b/internal/pkg/cli/deploy/lbws.go @@ -142,13 +142,6 @@ func (d *lbWebSvcDeployer) stackConfiguration(in *StackRuntimeConfiguration) (*s if err := d.validateNLBRuntime(); err != nil { return nil, err } - var appHostedZoneID string - if d.app.Domain != "" { - appHostedZoneID, err = appDomainHostedZoneId(d.app.Name, d.app.Domain, d.domainHostedZoneGetter) - if err != nil { - return nil, err - } - } var opts []stack.LoadBalancedWebServiceOption if d.lbMft.HTTPOrBool.ImportedALB != nil { lb, err := d.elbGetter.LoadBalancer(aws.StringValue(d.lbMft.HTTPOrBool.ImportedALB)) @@ -173,7 +166,6 @@ func (d *lbWebSvcDeployer) stackConfiguration(in *StackRuntimeConfiguration) (*s RuntimeConfig: *rc, RootUserARN: in.RootUserARN, Addons: d.addons, - AppHostedZoneID: appHostedZoneID, }, opts...) if err != nil { return nil, fmt.Errorf("create stack configuration: %w", err) diff --git a/internal/pkg/cli/deploy/mocks/mock_env.go b/internal/pkg/cli/deploy/mocks/mock_env.go index 3fcbe918c7a..c1982de6a8b 100644 --- a/internal/pkg/cli/deploy/mocks/mock_env.go +++ b/internal/pkg/cli/deploy/mocks/mock_env.go @@ -453,41 +453,3 @@ func (mr *MockstackDescriberMockRecorder) Resources() *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Resources", reflect.TypeOf((*MockstackDescriber)(nil).Resources)) } - -// MockdomainHostedZoneGetter is a mock of domainHostedZoneGetter interface. -type MockdomainHostedZoneGetter struct { - ctrl *gomock.Controller - recorder *MockdomainHostedZoneGetterMockRecorder -} - -// MockdomainHostedZoneGetterMockRecorder is the mock recorder for MockdomainHostedZoneGetter. -type MockdomainHostedZoneGetterMockRecorder struct { - mock *MockdomainHostedZoneGetter -} - -// NewMockdomainHostedZoneGetter creates a new mock instance. -func NewMockdomainHostedZoneGetter(ctrl *gomock.Controller) *MockdomainHostedZoneGetter { - mock := &MockdomainHostedZoneGetter{ctrl: ctrl} - mock.recorder = &MockdomainHostedZoneGetterMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockdomainHostedZoneGetter) EXPECT() *MockdomainHostedZoneGetterMockRecorder { - return m.recorder -} - -// PublicDomainHostedZoneID mocks base method. -func (m *MockdomainHostedZoneGetter) PublicDomainHostedZoneID(domainName string) (string, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PublicDomainHostedZoneID", domainName) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PublicDomainHostedZoneID indicates an expected call of PublicDomainHostedZoneID. -func (mr *MockdomainHostedZoneGetterMockRecorder) PublicDomainHostedZoneID(domainName interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PublicDomainHostedZoneID", reflect.TypeOf((*MockdomainHostedZoneGetter)(nil).PublicDomainHostedZoneID), domainName) -} diff --git a/internal/pkg/cli/deploy/rdws.go b/internal/pkg/cli/deploy/rdws.go index afbdc9c11a8..82cb3fbde0b 100644 --- a/internal/pkg/cli/deploy/rdws.go +++ b/internal/pkg/cli/deploy/rdws.go @@ -143,11 +143,10 @@ func (d *rdwsDeployer) stackConfiguration(in *StackRuntimeConfiguration) (*rdwsS default: conf, err = stack.NewRequestDrivenWebService(stack.RequestDrivenWebServiceConfig{ App: deploy.AppInformation{ - Name: d.app.Name, - Domain: d.app.Domain, - PermissionsBoundary: d.app.PermissionsBoundary, - AccountPrincipalARN: in.RootUserARN, - RootDomainHostedZoneId: d.app.DomainHostedZoneID, + Name: d.app.Name, + Domain: d.app.Domain, + PermissionsBoundary: d.app.PermissionsBoundary, + AccountPrincipalARN: in.RootUserARN, }, Env: d.env.Name, Manifest: d.rdwsMft, diff --git a/internal/pkg/cli/deploy/static_site.go b/internal/pkg/cli/deploy/static_site.go index 794825e23e3..780e049fb74 100644 --- a/internal/pkg/cli/deploy/static_site.go +++ b/internal/pkg/cli/deploy/static_site.go @@ -163,13 +163,6 @@ func (d *staticSiteDeployer) stackConfiguration(in *StackRuntimeConfiguration) ( if err := validateMinAppVersion(d.app.Name, d.name, d.appVersionGetter, version.AppTemplateMinStaticSite); err != nil { return nil, fmt.Errorf("static sites not supported: %w", err) } - var appHostedZoneID string - if d.app.Domain != "" { - appHostedZoneID, err = appDomainHostedZoneId(d.app.Name, d.app.Domain, d.domainHostedZoneGetter) - if err != nil { - return nil, err - } - } conf, err := d.newStack(&stack.StaticSiteConfig{ App: d.app, @@ -182,7 +175,6 @@ func (d *staticSiteDeployer) stackConfiguration(in *StackRuntimeConfiguration) ( RootUserARN: in.RootUserARN, Addons: d.addons, AssetMappingURL: in.StaticSiteAssetMappingURL, - AppHostedZoneID: appHostedZoneID, }) if err != nil { return nil, fmt.Errorf("create stack configuration: %w", err) diff --git a/internal/pkg/cli/deploy/static_site_test.go b/internal/pkg/cli/deploy/static_site_test.go index 74727d70a61..0b5b29f2eae 100644 --- a/internal/pkg/cli/deploy/static_site_test.go +++ b/internal/pkg/cli/deploy/static_site_test.go @@ -139,7 +139,6 @@ func TestStaticSiteDeployer_UploadArtifacts(t *testing.T) { func TestStaticSiteDeployer_stackConfiguration(t *testing.T) { tests := map[string]struct { - setUpMocks func(m *mocks.MockdomainHostedZoneGetter) deployer *staticSiteDeployer wantErr string wantTemplate string @@ -331,9 +330,6 @@ func TestStaticSiteDeployer_stackConfiguration(t *testing.T) { }, }, "success with app alias": { - setUpMocks: func(m *mocks.MockdomainHostedZoneGetter) { - m.EXPECT().PublicDomainHostedZoneID(fmt.Sprintf("%s.%s", "mockApp", "example.com")).Return("Z00AB", nil).Return("Z00AB", nil) - }, deployer: &staticSiteDeployer{ svcDeployer: &svcDeployer{ workloadDeployer: &workloadDeployer{ @@ -406,9 +402,6 @@ func TestStaticSiteDeployer_stackConfiguration(t *testing.T) { }, }, "success with overrider": { - setUpMocks: func(m *mocks.MockdomainHostedZoneGetter) { - m.EXPECT().PublicDomainHostedZoneID(fmt.Sprintf("%s.%s", "mockApp", "example.com")).Return("Z00AB", nil) - }, deployer: &staticSiteDeployer{ svcDeployer: &svcDeployer{ workloadDeployer: &workloadDeployer{ @@ -450,13 +443,6 @@ func TestStaticSiteDeployer_stackConfiguration(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - if tc.setUpMocks != nil { - mocks := mocks.NewMockdomainHostedZoneGetter(ctrl) - tc.setUpMocks(mocks) - tc.deployer.domainHostedZoneGetter = mocks - } out, gotErr := tc.deployer.stackConfiguration(&StackRuntimeConfiguration{}) if tc.wantErr != "" { require.EqualError(t, gotErr, tc.wantErr) diff --git a/internal/pkg/cli/deploy/workload.go b/internal/pkg/cli/deploy/workload.go index 37b93b6f533..8ca10485727 100644 --- a/internal/pkg/cli/deploy/workload.go +++ b/internal/pkg/cli/deploy/workload.go @@ -24,7 +24,6 @@ import ( "github.com/aws/copilot-cli/internal/pkg/aws/ecr" "github.com/aws/copilot-cli/internal/pkg/aws/identity" "github.com/aws/copilot-cli/internal/pkg/aws/partitions" - "github.com/aws/copilot-cli/internal/pkg/aws/route53" "github.com/aws/copilot-cli/internal/pkg/aws/s3" "github.com/aws/copilot-cli/internal/pkg/aws/sessions" "github.com/aws/copilot-cli/internal/pkg/config" @@ -181,21 +180,20 @@ type workloadDeployer struct { workspacePath string // Dependencies. - fs afero.Fs - s3Client uploader - addons stackBuilder - repository repositoryService - deployer serviceDeployer - tmplGetter deployedTemplateGetter - endpointGetter endpointGetter - spinner spinner - templateFS template.Reader - envVersionGetter versionGetter - overrider Overrider - docker dockerEngineRunChecker - customResources customResourcesFunc - labeledTermPrinter func(fw syncbuffer.FileWriter, bufs []*syncbuffer.LabeledSyncBuffer, opts ...syncbuffer.LabeledTermPrinterOption) LabeledTermPrinter - domainHostedZoneGetter domainHostedZoneGetter + fs afero.Fs + s3Client uploader + addons stackBuilder + repository repositoryService + deployer serviceDeployer + tmplGetter deployedTemplateGetter + endpointGetter endpointGetter + spinner spinner + templateFS template.Reader + envVersionGetter versionGetter + overrider Overrider + docker dockerEngineRunChecker + customResources customResourcesFunc + labeledTermPrinter func(fw syncbuffer.FileWriter, bufs []*syncbuffer.LabeledSyncBuffer, opts ...syncbuffer.LabeledTermPrinterOption) LabeledTermPrinter // Cached variables. defaultSess *session.Session @@ -337,7 +335,6 @@ func newWorkloadDeployer(in *WorkloadDeployerInput) (*workloadDeployer, error) { store: store, envConfig: envConfig, labeledTermPrinter: labeledTermPrinter, - domainHostedZoneGetter: route53.New(defaultSession), mft: in.Mft, rawMft: in.RawMft, diff --git a/internal/pkg/cli/deploy/workload_test.go b/internal/pkg/cli/deploy/workload_test.go index 90acff9d9ab..8b18c76be80 100644 --- a/internal/pkg/cli/deploy/workload_test.go +++ b/internal/pkg/cli/deploy/workload_test.go @@ -61,7 +61,6 @@ type deployMocks struct { mockValidator *mocks.MockaliasCertValidator mockLabeledTermPrinter *mocks.MockLabeledTermPrinter mockdockerEngineRunChecker *mocks.MockdockerEngineRunChecker - mockdomainHostedZonegetter *mocks.MockdomainHostedZoneGetter } type mockTemplateFS struct { @@ -1211,7 +1210,6 @@ func TestWorkloadDeployer_DeployWorkload(t *testing.T) { m.mockEndpointGetter.EXPECT().ServiceDiscoveryEndpoint().Return("mockApp.local", nil) m.mockEnvVersionGetter.EXPECT().Version().Return("v1.42.0", nil) m.mockServiceDeployer.EXPECT().DeployService(gomock.Any(), "mockBucket", false, gomock.Any()).Return(nil) - m.mockdomainHostedZonegetter.EXPECT().PublicDomainHostedZoneID(fmt.Sprintf("%s.%s", mockAppName, "mockDomain")).Return("Z00ABC", nil) }, }, "success": { @@ -1236,7 +1234,6 @@ func TestWorkloadDeployer_DeployWorkload(t *testing.T) { m.mockEnvVersionGetter.EXPECT().Version().Return("v1.42.0", nil) m.mockValidator.EXPECT().ValidateCertAliases([]string{"example.com", "foobar.com"}, mockCertARNs).Return(nil).Times(2) m.mockServiceDeployer.EXPECT().DeployService(gomock.Any(), "mockBucket", false, gomock.Any()).Return(nil) - m.mockdomainHostedZonegetter.EXPECT().PublicDomainHostedZoneID(fmt.Sprintf("%s.%s", mockAppName, "mockDomain")).Return("Z00ABC", nil) }, }, "success with http redirect disabled and alb certs imported": { @@ -1312,7 +1309,6 @@ func TestWorkloadDeployer_DeployWorkload(t *testing.T) { m.mockEnvVersionGetter.EXPECT().Version().Return("v1.42.0", nil) m.mockAppVersionGetter.EXPECT().Version().Return("v1.0.0", nil).Times(2) m.mockServiceDeployer.EXPECT().DeployService(gomock.Any(), "mockBucket", false, gomock.Any()).Return(nil) - m.mockdomainHostedZonegetter.EXPECT().PublicDomainHostedZoneID(fmt.Sprintf("%s.%s", mockAppName, "mockDomain")).Return("Z00ABC", nil) }, }, "success with force update": { @@ -1344,14 +1340,13 @@ func TestWorkloadDeployer_DeployWorkload(t *testing.T) { defer ctrl.Finish() m := &deployMocks{ - mockAppVersionGetter: mocks.NewMockversionGetter(ctrl), - mockEnvVersionGetter: mocks.NewMockversionGetter(ctrl), - mockEndpointGetter: mocks.NewMockendpointGetter(ctrl), - mockServiceDeployer: mocks.NewMockserviceDeployer(ctrl), - mockServiceForceUpdater: mocks.NewMockserviceForceUpdater(ctrl), - mockSpinner: mocks.NewMockspinner(ctrl), - mockValidator: mocks.NewMockaliasCertValidator(ctrl), - mockdomainHostedZonegetter: mocks.NewMockdomainHostedZoneGetter(ctrl), + mockAppVersionGetter: mocks.NewMockversionGetter(ctrl), + mockEnvVersionGetter: mocks.NewMockversionGetter(ctrl), + mockEndpointGetter: mocks.NewMockendpointGetter(ctrl), + mockServiceDeployer: mocks.NewMockserviceDeployer(ctrl), + mockServiceForceUpdater: mocks.NewMockserviceForceUpdater(ctrl), + mockSpinner: mocks.NewMockspinner(ctrl), + mockValidator: mocks.NewMockaliasCertValidator(ctrl), } tc.mock(m) @@ -1363,17 +1358,16 @@ func TestWorkloadDeployer_DeployWorkload(t *testing.T) { deployer := lbWebSvcDeployer{ svcDeployer: &svcDeployer{ workloadDeployer: &workloadDeployer{ - name: mockName, - app: tc.inApp, - env: tc.inEnvironment, - envConfig: tc.inEnvironmentConfig(), - resources: mockResources, - deployer: m.mockServiceDeployer, - endpointGetter: m.mockEndpointGetter, - spinner: m.mockSpinner, - envVersionGetter: m.mockEnvVersionGetter, - overrider: new(override.Noop), - domainHostedZoneGetter: m.mockdomainHostedZonegetter, + name: mockName, + app: tc.inApp, + env: tc.inEnvironment, + envConfig: tc.inEnvironmentConfig(), + resources: mockResources, + deployer: m.mockServiceDeployer, + endpointGetter: m.mockEndpointGetter, + spinner: m.mockSpinner, + envVersionGetter: m.mockEnvVersionGetter, + overrider: new(override.Noop), }, newSvcUpdater: func(f func(*session.Session) serviceForceUpdater) serviceForceUpdater { return m.mockServiceForceUpdater diff --git a/internal/pkg/deploy/app.go b/internal/pkg/deploy/app.go index 50c060df389..0ec649571c9 100644 --- a/internal/pkg/deploy/app.go +++ b/internal/pkg/deploy/app.go @@ -27,12 +27,10 @@ type CreateAppInput struct { // AppInformation holds information about the application that need to be propagated to the env stacks and workload stacks. type AppInformation struct { - AccountPrincipalARN string - Domain string - Name string - PermissionsBoundary string - RootDomainHostedZoneId string - AppDomainHostedZoneId string + AccountPrincipalARN string + Domain string + Name string + PermissionsBoundary string } // DNSDelegationRole returns the ARN of the app's DNS delegation role. diff --git a/internal/pkg/deploy/cloudformation/stack/env.go b/internal/pkg/deploy/cloudformation/stack/env.go index 8b82e5f978d..fa14cf61574 100644 --- a/internal/pkg/deploy/cloudformation/stack/env.go +++ b/internal/pkg/deploy/cloudformation/stack/env.go @@ -219,7 +219,6 @@ func (e *Env) Template() (string, error) { SerializedManifest: string(e.in.RawMft), ForceUpdateID: forceUpdateID, DelegateDNS: e.in.App.Domain != "", - HostedZones: convertHostedZones(e.in.App), }) if err != nil { return "", err diff --git a/internal/pkg/deploy/cloudformation/stack/env_test.go b/internal/pkg/deploy/cloudformation/stack/env_test.go index 124ed256a17..e6681b130b1 100644 --- a/internal/pkg/deploy/cloudformation/stack/env_test.go +++ b/internal/pkg/deploy/cloudformation/stack/env_test.go @@ -134,9 +134,6 @@ func TestEnv_Template(t *testing.T) { // GIVEN inEnvConfig := mockDeployEnvironmentInput() - inEnvConfig.App.Domain = "example.com" - inEnvConfig.App.RootDomainHostedZoneId = "Z00ABC" - inEnvConfig.App.AppDomainHostedZoneId = "Z00DEF" mockParser := mocks.NewMockembedFS(ctrl) mockParser.EXPECT().Read(gomock.Any()).Return(&template.Content{Buffer: bytes.NewBufferString("data")}, nil).AnyTimes() mockParser.EXPECT().ParseEnv(gomock.Any()).DoAndReturn(func(data *template.EnvOpts) (*template.Content, error) { @@ -173,11 +170,6 @@ func TestEnv_Template(t *testing.T) { ArtifactBucketARN: "arn:aws:s3:::mockbucket", SerializedManifest: "name: env\ntype: Environment\n", ForceUpdateID: "mockPreviousForceUpdateID", - DelegateDNS: true, - HostedZones: &template.HostedZones{ - RootDomainHostedZoneId: "Z00ABC", - AppDomainHostedZoneId: "Z00DEF", - }, }, data) return &template.Content{Buffer: bytes.NewBufferString("mockTemplate")}, nil }) diff --git a/internal/pkg/deploy/cloudformation/stack/lb_network_web_service_integration_test.go b/internal/pkg/deploy/cloudformation/stack/lb_network_web_service_integration_test.go index 724362da0d3..889f99a6e35 100644 --- a/internal/pkg/deploy/cloudformation/stack/lb_network_web_service_integration_test.go +++ b/internal/pkg/deploy/cloudformation/stack/lb_network_web_service_integration_test.go @@ -102,7 +102,7 @@ func TestNetworkLoadBalancedWebService_Template(t *testing.T) { }, } serializer, err := stack.NewLoadBalancedWebService(stack.LoadBalancedWebServiceConfig{ - App: &config.Application{Name: appName, Domain: "example.com", DomainHostedZoneID: "Z00ABC"}, + App: &config.Application{Name: appName, Domain: "example.com"}, EnvManifest: envConfig, Manifest: v, ArtifactBucketName: "bucket", @@ -114,8 +114,7 @@ func TestNetworkLoadBalancedWebService_Template(t *testing.T) { EnvVersion: "v1.42.0", Version: "v1.29.0", }, - RootUserARN: "arn:aws:iam::123456789123:root", - AppHostedZoneID: "Z00DEF", + RootUserARN: "arn:aws:iam::123456789123:root", }) tpl, err := serializer.Template() require.NoError(t, err, "template should render") diff --git a/internal/pkg/deploy/cloudformation/stack/lb_web_svc.go b/internal/pkg/deploy/cloudformation/stack/lb_web_svc.go index e906deabde8..1f1c2a3bbfe 100644 --- a/internal/pkg/deploy/cloudformation/stack/lb_web_svc.go +++ b/internal/pkg/deploy/cloudformation/stack/lb_web_svc.go @@ -61,7 +61,6 @@ type LoadBalancedWebServiceConfig struct { ArtifactBucketName string ArtifactKey string Addons NestedStackConfigurer - AppHostedZoneID string } // NewLoadBalancedWebService creates a new CFN stack with an ECS service from a manifest file, given the options. @@ -78,11 +77,9 @@ func NewLoadBalancedWebService(conf LoadBalancedWebServiceConfig, if conf.App.Domain != "" { dnsDelegationEnabled = true appInfo = deploy.AppInformation{ - Name: conf.App.Name, - Domain: conf.App.Domain, - AccountPrincipalARN: conf.RootUserARN, - RootDomainHostedZoneId: conf.App.DomainHostedZoneID, - AppDomainHostedZoneId: conf.AppHostedZoneID, + Name: conf.App.Name, + Domain: conf.App.Domain, + AccountPrincipalARN: conf.RootUserARN, } httpsEnabled = true } @@ -243,7 +240,6 @@ func (s *LoadBalancedWebService) Template() (string, error) { // NLB configs. AppDNSName: nlbConfig.appDNSName, AppDNSDelegationRole: nlbConfig.appDNSDelegationRole, - HostedZones: convertHostedZones(s.appInfo), NLB: nlbConfig.settings, // service connect and service discovery options. diff --git a/internal/pkg/deploy/cloudformation/stack/lb_web_svc_test.go b/internal/pkg/deploy/cloudformation/stack/lb_web_svc_test.go index 3679ecb1e95..fd8deb15530 100644 --- a/internal/pkg/deploy/cloudformation/stack/lb_web_svc_test.go +++ b/internal/pkg/deploy/cloudformation/stack/lb_web_svc_test.go @@ -233,9 +233,8 @@ Outputs: lbws, err := NewLoadBalancedWebService(LoadBalancedWebServiceConfig{ App: &config.Application{ - Name: "phonetool", - Domain: "phonetool.com", - DomainHostedZoneID: "Z00ABC", + Name: "phonetool", + Domain: "phonetool.com", }, EnvManifest: &manifest.Environment{ Workload: manifest.Workload{ @@ -255,7 +254,6 @@ Outputs: }, Addons: mockAddons{}, ArtifactBucketName: "bucket", - AppHostedZoneID: "Z00DEF", }, func(s *LoadBalancedWebService) { s.parser = parser }) @@ -355,10 +353,6 @@ Outputs: ContainerName: "frontend", }, }, - HostedZones: &template.HostedZones{ - RootDomainHostedZoneId: "Z00ABC", - AppDomainHostedZoneId: "Z00DEF", - }, }, actual) }) diff --git a/internal/pkg/deploy/cloudformation/stack/rd_web_svc.go b/internal/pkg/deploy/cloudformation/stack/rd_web_svc.go index 53d9f3a2a20..8d77cd2f025 100644 --- a/internal/pkg/deploy/cloudformation/stack/rd_web_svc.go +++ b/internal/pkg/deploy/cloudformation/stack/rd_web_svc.go @@ -150,7 +150,6 @@ func (s *RequestDrivenWebService) Template() (string, error) { AppRunnerVPCEndpoint: s.manifest.Private.Advanced.Endpoint, Count: s.manifest.Count, Secrets: convertSecrets(s.manifest.RequestDrivenWebServiceConfig.Secrets), - HostedZones: convertHostedZones(s.app), }) if err != nil { return "", err diff --git a/internal/pkg/deploy/cloudformation/stack/static_site.go b/internal/pkg/deploy/cloudformation/stack/static_site.go index 40cd2511a27..2bcd8e6cd5c 100644 --- a/internal/pkg/deploy/cloudformation/stack/static_site.go +++ b/internal/pkg/deploy/cloudformation/stack/static_site.go @@ -40,7 +40,6 @@ type StaticSiteConfig struct { ArtifactKey string Addons NestedStackConfigurer AssetMappingURL string - AppHostedZoneID string } // NewStaticSite creates a new CFN stack from a manifest file, given the options. @@ -56,11 +55,9 @@ func NewStaticSite(cfg *StaticSiteConfig) (*StaticSite, error) { if cfg.App.Domain != "" { dnsDelegationEnabled = true appInfo = deploy.AppInformation{ - Name: cfg.App.Name, - Domain: cfg.App.Domain, - AccountPrincipalARN: cfg.RootUserARN, - RootDomainHostedZoneId: cfg.App.DomainHostedZoneID, - AppDomainHostedZoneId: cfg.AppHostedZoneID, + Name: cfg.App.Name, + Domain: cfg.App.Domain, + AccountPrincipalARN: cfg.RootUserARN, } } return &StaticSite{ @@ -138,7 +135,6 @@ func (s *StaticSite) Template() (string, error) { AppDNSName: dnsName, AppDNSDelegationRole: dnsDelegationRole, - HostedZones: convertHostedZones(s.appInfo), AssetMappingFileBucket: bucket, AssetMappingFilePath: path, StaticSiteAlias: staticSiteAlias, diff --git a/internal/pkg/deploy/cloudformation/stack/static_site_integration_test.go b/internal/pkg/deploy/cloudformation/stack/static_site_integration_test.go index cb965e3861e..d26f042f953 100644 --- a/internal/pkg/deploy/cloudformation/stack/static_site_integration_test.go +++ b/internal/pkg/deploy/cloudformation/stack/static_site_integration_test.go @@ -91,9 +91,8 @@ func TestStaticSiteService_TemplateAndParamsGeneration(t *testing.T) { } serializer, err := stack.NewStaticSite(&stack.StaticSiteConfig{ App: &config.Application{ - Name: appName, - Domain: "example.com", - DomainHostedZoneID: "Z00ABC", + Name: appName, + Domain: "example.com", }, EnvManifest: envConfig, Manifest: v, @@ -106,7 +105,6 @@ func TestStaticSiteService_TemplateAndParamsGeneration(t *testing.T) { ArtifactKey: "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", AssetMappingURL: "s3://stackset-bucket/mappingfile", RootUserARN: "arn:aws:iam::123456789123:root", - AppHostedZoneID: "Z00DEF", }) require.NoError(t, err, "stack should be able to be initialized") tpl, err := serializer.Template() diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-basic-manifest.yml b/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-basic-manifest.yml index cb0cb460c7d..1d6200f74da 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-basic-manifest.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-basic-manifest.yml @@ -972,7 +972,6 @@ Resources: SubdomainName: !Sub ${EnvironmentName}.${AppName}.${AppDNSName} NameServers: !GetAtt EnvironmentHostedZone.NameServers RootDNSRole: !Ref AppDNSDelegationRole - EnvHostedZoneId: !Ref EnvironmentHostedZone HTTPSCert: Metadata: @@ -1005,7 +1004,6 @@ Resources: Aliases: !Ref Aliases AppDNSRole: !Ref AppDNSDelegationRole DomainName: !Ref AppDNSName - EnvHostedZoneId: !Ref EnvironmentHostedZone PublicAccessDNS: !GetAtt PublicLoadBalancer.DNSName PublicAccessHostedZone: !GetAtt PublicLoadBalancer.CanonicalHostedZoneID AppRunnerVpcEndpointSecurityGroup: diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-default-access-log-config.yml b/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-default-access-log-config.yml index ec9825c9eda..69d8ab439e6 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-default-access-log-config.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-default-access-log-config.yml @@ -1128,7 +1128,6 @@ Resources: SubdomainName: !Sub ${EnvironmentName}.${AppName}.${AppDNSName} NameServers: !GetAtt EnvironmentHostedZone.NameServers RootDNSRole: !Ref AppDNSDelegationRole - EnvHostedZoneId: !Ref EnvironmentHostedZone HTTPSCert: Metadata: @@ -1161,7 +1160,6 @@ Resources: Aliases: !Ref Aliases AppDNSRole: !Ref AppDNSDelegationRole DomainName: !Ref AppDNSName - EnvHostedZoneId: !Ref EnvironmentHostedZone PublicAccessDNS: !GetAtt PublicLoadBalancer.DNSName PublicAccessHostedZone: !GetAtt PublicLoadBalancer.CanonicalHostedZoneID AppRunnerVpcEndpointSecurityGroup: diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-defaultvpc-flowlogs.yml b/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-defaultvpc-flowlogs.yml index a31a995ca6e..9b5da1748cb 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-defaultvpc-flowlogs.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-defaultvpc-flowlogs.yml @@ -978,7 +978,6 @@ Resources: SubdomainName: !Sub ${EnvironmentName}.${AppName}.${AppDNSName} NameServers: !GetAtt EnvironmentHostedZone.NameServers RootDNSRole: !Ref AppDNSDelegationRole - EnvHostedZoneId: !Ref EnvironmentHostedZone HTTPSCert: Metadata: @@ -1011,7 +1010,6 @@ Resources: Aliases: !Ref Aliases AppDNSRole: !Ref AppDNSDelegationRole DomainName: !Ref AppDNSName - EnvHostedZoneId: !Ref EnvironmentHostedZone PublicAccessDNS: !GetAtt PublicLoadBalancer.DNSName PublicAccessHostedZone: !GetAtt PublicLoadBalancer.CanonicalHostedZoneID VpcFlowLogGroup: diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-importedvpc-flowlogs.yml b/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-importedvpc-flowlogs.yml index 758d670aaf8..96c67300756 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-importedvpc-flowlogs.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/environments/template-with-importedvpc-flowlogs.yml @@ -807,7 +807,6 @@ Resources: SubdomainName: !Sub ${EnvironmentName}.${AppName}.${AppDNSName} NameServers: !GetAtt EnvironmentHostedZone.NameServers RootDNSRole: !Ref AppDNSDelegationRole - EnvHostedZoneId: !Ref EnvironmentHostedZone HTTPSCert: Metadata: @@ -840,7 +839,6 @@ Resources: Aliases: !Ref Aliases AppDNSRole: !Ref AppDNSDelegationRole DomainName: !Ref AppDNSName - EnvHostedZoneId: !Ref EnvironmentHostedZone PublicAccessDNS: !GetAtt PublicLoadBalancer.DNSName PublicAccessHostedZone: !GetAtt PublicLoadBalancer.CanonicalHostedZoneID VpcFlowLogGroup: diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/static-site.stack.yml b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/static-site.stack.yml index 2f05401cedf..5a6b10fba51 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/static-site.stack.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/static-site.stack.yml @@ -378,8 +378,6 @@ Resources: RootDNSRole: arn:aws:iam::123456789123:role/my-app-DNSDelegationRole DomainName: example.com Aliases: ["*.example.com"] - RootHostedZoneId: "Z00ABC" - AppHostedZoneId: "Z00DEF" CustomDomainFunction: Type: AWS::Lambda::Function @@ -442,8 +440,6 @@ Resources: DomainName: example.com IsCloudFrontCertificate: true Aliases: ["*.example.com"] - RootHostedZoneId: "Z00ABC" - AppHostedZoneId: "Z00DEF" CertificateValidationFunction: Type: AWS::Lambda::Function diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-nlb-prod.stack.yml b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-nlb-prod.stack.yml index 93846de570f..ac770d4d3a0 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-nlb-prod.stack.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-nlb-prod.stack.yml @@ -619,8 +619,6 @@ Resources: # If a bucket URL is specified, that means the template exists. DomainName: example.com Aliases: - nlb.example.com - RootHostedZoneId: "Z00ABC" - AppHostedZoneId: "Z00DEF" NLBCustomDomainFunction: Type: AWS::Lambda::Function Condition: HasAssociatedDomain @@ -686,8 +684,6 @@ Resources: # If a bucket URL is specified, that means the template exists. DomainName: example.com Aliases: - nlb.example.com - RootHostedZoneId: "Z00ABC" - AppHostedZoneId: "Z00DEF" NLBCertValidatorFunction: Type: AWS::Lambda::Function Condition: HasAssociatedDomain diff --git a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-nlb-test.stack.yml b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-nlb-test.stack.yml index 23bfd98c1f2..6263177a018 100644 --- a/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-nlb-test.stack.yml +++ b/internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-nlb-test.stack.yml @@ -507,8 +507,6 @@ Resources: # If a bucket URL is specified, that means the template exists. RootDNSRole: arn:aws:iam::123456789123:role/my-app-DNSDelegationRole DomainName: example.com Aliases: [] - RootHostedZoneId: "Z00ABC" - AppHostedZoneId: "Z00DEF" NLBCertValidatorFunction: Type: AWS::Lambda::Function Condition: HasAssociatedDomain diff --git a/internal/pkg/deploy/cloudformation/stack/transformers.go b/internal/pkg/deploy/cloudformation/stack/transformers.go index 1a120b8c1ad..77042537593 100644 --- a/internal/pkg/deploy/cloudformation/stack/transformers.go +++ b/internal/pkg/deploy/cloudformation/stack/transformers.go @@ -1357,13 +1357,3 @@ func (in uploadableCRs) convert() []uploadable { } return out } - -func convertHostedZones(app deploy.AppInformation) *template.HostedZones { - if app.Domain == "" { - return nil - } - return &template.HostedZones{ - RootDomainHostedZoneId: app.RootDomainHostedZoneId, - AppDomainHostedZoneId: app.AppDomainHostedZoneId, - } -} diff --git a/internal/pkg/template/env.go b/internal/pkg/template/env.go index 059f95b9ec2..61e59db8718 100644 --- a/internal/pkg/template/env.go +++ b/internal/pkg/template/env.go @@ -138,7 +138,6 @@ type EnvOpts struct { ForceUpdateID string DelegateDNS bool - HostedZones *HostedZones } // PublicHTTPConfig represents configuration for a public facing Load Balancer. @@ -245,12 +244,6 @@ type VPCFlowLogs struct { Retention *int } -// HostedZones represents copilot managed hostedzones to route traffic to specific domain. -type HostedZones struct { - RootDomainHostedZoneId string - AppDomainHostedZoneId string -} - // ParseEnv parses an environment's CloudFormation template with the specified data object and returns its content. func (t *Template) ParseEnv(data *EnvOpts) (*Content, error) { tpl, err := t.parse("base", envCFTemplatePath, withEnvParsingFuncs()) diff --git a/internal/pkg/template/templates/environment/partials/custom-resources.yml b/internal/pkg/template/templates/environment/partials/custom-resources.yml index 9f55e84bac5..178da537b61 100644 --- a/internal/pkg/template/templates/environment/partials/custom-resources.yml +++ b/internal/pkg/template/templates/environment/partials/custom-resources.yml @@ -12,11 +12,6 @@ DelegateDNSAction: SubdomainName: !Sub ${EnvironmentName}.${AppName}.${AppDNSName} NameServers: !GetAtt EnvironmentHostedZone.NameServers RootDNSRole: !Ref AppDNSDelegationRole - EnvHostedZoneId: !Ref EnvironmentHostedZone - {{- if .HostedZones}} - RootHostedZoneId: {{.HostedZones.RootDomainHostedZoneId}} - AppHostedZoneId: {{.HostedZones.AppDomainHostedZoneId}} - {{- end}} HTTPSCert: Metadata: @@ -36,11 +31,6 @@ HTTPSCert: EnvHostedZoneId: !Ref EnvironmentHostedZone Region: !Ref AWS::Region RootDNSRole: !Ref AppDNSDelegationRole - {{- if .HostedZones}} - RootHostedZoneId: {{.HostedZones.RootDomainHostedZoneId}} - AppHostedZoneId: {{.HostedZones.AppDomainHostedZoneId}} - {{- end}} - CustomDomainAction: Metadata: @@ -54,15 +44,10 @@ CustomDomainAction: Aliases: !Ref Aliases AppDNSRole: !Ref AppDNSDelegationRole DomainName: !Ref AppDNSName - EnvHostedZoneId: !Ref EnvironmentHostedZone {{- if .CDNConfig}} PublicAccessDNS: !GetAtt CloudFrontDistribution.DomainName PublicAccessHostedZone: Z2FDTNDATAQYW2 # See https://go.aws/3cPhvlX {{- else}} PublicAccessDNS: !GetAtt PublicLoadBalancer.DNSName PublicAccessHostedZone: !GetAtt PublicLoadBalancer.CanonicalHostedZoneID - {{- end}} - {{- if .HostedZones}} - RootHostedZoneId: {{.HostedZones.RootDomainHostedZoneId}} - AppHostedZoneId: {{.HostedZones.AppDomainHostedZoneId}} - {{- end}} \ No newline at end of file + {{- end}} \ No newline at end of file diff --git a/internal/pkg/template/templates/workloads/partials/cf/nlb.yml b/internal/pkg/template/templates/workloads/partials/cf/nlb.yml index 7994c5f4443..20b1f29746d 100644 --- a/internal/pkg/template/templates/workloads/partials/cf/nlb.yml +++ b/internal/pkg/template/templates/workloads/partials/cf/nlb.yml @@ -139,10 +139,6 @@ NLBCustomDomainAction: RootDNSRole: {{ .AppDNSDelegationRole }} DomainName: {{ .AppDNSName }} Aliases: {{ if .NLB.Aliases }} {{ fmtSlice .NLB.Aliases }} {{ else }} [] {{ end }} - {{- if .HostedZones}} - RootHostedZoneId: {{.HostedZones.RootDomainHostedZoneId}} - AppHostedZoneId: {{.HostedZones.AppDomainHostedZoneId}} - {{- end}} NLBCustomDomainFunction: Type: AWS::Lambda::Function @@ -223,10 +219,6 @@ NLBCertValidatorAction: RootDNSRole: {{ .AppDNSDelegationRole }} DomainName: {{ .AppDNSName }} Aliases: {{ if .NLB.Aliases }} {{ fmtSlice .NLB.Aliases }} {{ else }} [] {{ end }} - {{- if .HostedZones}} - RootHostedZoneId: {{.HostedZones.RootDomainHostedZoneId}} - AppHostedZoneId: {{.HostedZones.AppDomainHostedZoneId}} - {{- end}} NLBCertValidatorFunction: Type: AWS::Lambda::Function diff --git a/internal/pkg/template/templates/workloads/services/rd-web/cf.yml b/internal/pkg/template/templates/workloads/services/rd-web/cf.yml index ff8bbe3d2ff..93ec10154a3 100644 --- a/internal/pkg/template/templates/workloads/services/rd-web/cf.yml +++ b/internal/pkg/template/templates/workloads/services/rd-web/cf.yml @@ -242,9 +242,6 @@ Resources: CustomDomain: {{ .Alias }} AppDNSRole: {{ .AppDNSDelegationRole }} AppDNSName: {{ .AppDNSName }} - {{- if .HostedZones}} - RootHostedZoneId: {{.HostedZones.RootDomainHostedZoneId}} - {{- end}} CustomResourceRole: Metadata: diff --git a/internal/pkg/template/templates/workloads/services/static-site/cf.yml b/internal/pkg/template/templates/workloads/services/static-site/cf.yml index 5458dd63b30..379c3306468 100644 --- a/internal/pkg/template/templates/workloads/services/static-site/cf.yml +++ b/internal/pkg/template/templates/workloads/services/static-site/cf.yml @@ -417,10 +417,6 @@ Resources: RootDNSRole: {{ .AppDNSDelegationRole }} DomainName: {{ .AppDNSName }} Aliases: {{ if .StaticSiteAlias }} [{{ quote .StaticSiteAlias }}] {{ else }} [] {{ end }} - {{- if .HostedZones}} - RootHostedZoneId: {{.HostedZones.RootDomainHostedZoneId}} - AppHostedZoneId: {{.HostedZones.AppDomainHostedZoneId}} - {{- end}} CustomDomainFunction: Type: AWS::Lambda::Function @@ -492,10 +488,6 @@ Resources: DomainName: {{ .AppDNSName }} IsCloudFrontCertificate: true Aliases: {{ if .StaticSiteAlias }} [{{ quote .StaticSiteAlias }}] {{ else }} [] {{ end }} - {{- if .HostedZones}} - RootHostedZoneId: {{.HostedZones.RootDomainHostedZoneId}} - AppHostedZoneId: {{.HostedZones.AppDomainHostedZoneId}} - {{- end}} CertificateValidationFunction: Type: AWS::Lambda::Function diff --git a/internal/pkg/template/workload.go b/internal/pkg/template/workload.go index 7a4ca172613..59bec6846e8 100644 --- a/internal/pkg/template/workload.go +++ b/internal/pkg/template/workload.go @@ -850,7 +850,6 @@ type WorkloadOpts struct { AWSSDKLayer *string AppDNSDelegationRole *string AppDNSName *string - HostedZones *HostedZones // Additional options for worker service templates. Subscribe *SubscribeOpts